SlideShare a Scribd company logo
1 of 108
Download to read offline
Constraint Handling Rules - What Else?
Thom Fr¨uhwirth
University of Ulm, Germany
Thom Fr¨uhwirth Constraint Handling Rules
What Researchers Say About CHR
One of the most powerful multiset rewriting languages.
Kazunori Ueda, Waseda University, Japan
Consistently outperforms Rete-based rule-based systems.
Peter Van Weert, K.U. Leuven
Significant speed up when executed on multi-core systems.
Edmund S. L. Lam, National University of Singapore
Lingua franca, a hub which collects and dispenses research e↵orts
from and to the various related fields.
Jon Sneyers, K.U. Leuven
Thom Fr¨uhwirth Constraint Handling Rules
Page 9 My first CHR programs | Multiset transformation | Minimum
Minimum I
Minimum program
min(N)  min(M) <=> N=<M | true.
I Computing minimum of multiset of numbers ni
I Numbers given as query min(n1), min(n2),..., min(nk)
I min(ni) means ni is potential minimum
I Simpagation rule takes two min constraints and removes the one
representing the larger value.
I Program continues until only one min constraint left
I This min constraint represents smallest value
Page 10 My first CHR programs | Multiset transformation | Minimum
Minimum II
Minimum program
min(N)  min(M) <=> N=<M | true.
I Rule corresponds to intuitive algorithm:
“Cross out larger numbers until one, the minimum remains”
I Illustrates use of multi-headed rule to iterate over data
I No explicit loops or recursion needed
I Keeps program code compact
I Makes program easier to analyze
Page 24 My first CHR programs | Multiset transformation | Greatest common divisor
Greatest common divisor (I)
XOR program
gcd(N)  gcd(M) <=> 0<N,N=<M | gcd(M-N).
I Computes greatest common divisor of natural number
represented as gcd(N)
I Result is remaining nonzero gcd constraint
Example computation
gcd(12),gcd(8)
gcd(8), gcd(4)
gcd(4), gcd(4)
gcd(4), gcd(0)
GCD
Page 29 My first CHR programs | Multiset transformation | Prime number Sieve of Eratosthenes
Prime sieve
Prime sieve (I)
sift @ prime(I)  prime(J) <=> J mod I =:= 0 | true.
I Rule removes multiples of each of the numbers
I Query: Prime number candidates from 2 to up to N
i.e. prime(2),prime(3),prime(4),...prime(N)
I Each number absorbs multiples of itself, eventually only prime
numbers remain
Example computation
prime(7), prime(6), prime(5), prime(4), prime(3), prime(2)
prime(7), prime(5), prime(4), prime(3), prime(2)
prime(7), prime(5), prime(3), prime(2)
Constraint Handling Rules (CHR)
Concurrent declarative programming language
and versatile computational formalism as well
Semantic foundation in classical and linear logic
E cient sequential and parallel execution model
Guaranteed properties such as anytime and online
algorithm properties
Powerful analysis methods for deciding e.g. program
equivalence
Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Part I
The CHR Language
1 The CHR Language
2 Operational Properties
3 Program Analysis
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Example Partial Order Constraint
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y Z ) XZ (transitivity)
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
|| [built-in solver]
AB ^ BA ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Example Partial Order Constraint
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y Z ) XZ (transitivity)
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
|| [built-in solver]
AB ^ BA ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Example Partial Order Constraint
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y Z ) XZ (transitivity)
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
|| [built-in solver]
AB ^ BA ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Example Partial Order Constraint
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y Z ) XZ (transitivity)
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
|| [built-in solver]
AB ^ BA ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Example Partial Order Constraint
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y Z ) XZ (transitivity)
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
|| [built-in solver]
AB ^ BA ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Example Partial Order Constraint
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y Z ) XZ (transitivity)
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
|| [built-in solver]
AB ^ BA ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Example Partial Order Constraint
XY , X=Y | true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y Z ) XZ (transitivity)
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
|| [built-in solver]
AB ^ BA ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Syntax and Declarative Semantics
Declarative Semantics
Simplification rule: H , C | B 8¯x (C ! (H $ 9¯y B))
Propagation rule: H ) C | B 8¯x (C ! (H ! 9¯y B))
Constraint Theory for Built-Ins
Head H: non-empty conjunction of CHR constraints
Guard C: conjunction of built-in constraints
Body B: conjunction of CHR and built-in constraints (goal)
Soundness and Completeness based on logical equivalence of states in a
computation.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Operational Semantics
Apply rules until exhaustion in any order (fixpoint computation).
Initial goal (query) 7!⇤
result (answer).
Simplify
If (H , C | B) rule with renamed fresh variables ¯x
and CT |= Gbuiltin ! 9¯x(H=H0
^ C)
then H0
^ G 7! G ^ H=H0
^ B
Propagate
If (H ) C | B) rule with renamed fresh variables ¯x
and CT |= Gbuiltin ! 9¯x(H=H0
^ C)
then H0
^ G 7! H0
^ G ^ H=H0
^ B
Refined operational semantics [Duck+, ICLP 2004]: Similar to procedure
calls, CHR constraints evaluated depth-first from left to right and rules
applied top-down in program text order. Active vs. Partner constraint.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Operational Semantics
Apply rules until exhaustion in any order (fixpoint computation).
Initial goal (query) 7!⇤
result (answer).
Simplify
If (H , C | B) rule with renamed fresh variables ¯x
and CT |= Gbuiltin ! 9¯x(H=H0
^ C)
then H0
^ G 7! G ^ H=H0
^ B
Propagate
If (H ) C | B) rule with renamed fresh variables ¯x
and CT |= Gbuiltin ! 9¯x(H=H0
^ C)
then H0
^ G 7! H0
^ G ^ H=H0
^ B
Refined operational semantics [Duck+, ICLP 2004]: Similar to procedure
calls, CHR constraints evaluated depth-first from left to right and rules
applied top-down in program text order. Active vs. Partner constraint.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Operational Semantics
Apply rules until exhaustion in any order (fixpoint computation).
Initial goal (query) 7!⇤
result (answer).
Simplify
If (H , C | B) rule with renamed fresh variables ¯x
and CT |= Gbuiltin ! 9¯x(H=H0
^ C)
then H0
^ G 7! G ^ H=H0
^ B
Propagate
If (H ) C | B) rule with renamed fresh variables ¯x
and CT |= Gbuiltin ! 9¯x(H=H0
^ C)
then H0
^ G 7! H0
^ G ^ H=H0
^ B
Refined operational semantics [Duck+, ICLP 2004]: Similar to procedure
calls, CHR constraints evaluated depth-first from left to right and rules
applied top-down in program text order. Active vs. Partner constraint.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Operational Semantics
Apply rules until exhaustion in any order (fixpoint computation).
Initial goal (query) 7!⇤
result (answer).
Simplify
If (H , C | B) rule with renamed fresh variables ¯x
and CT |= Gbuiltin ! 9¯x(H=H0
^ C)
then H0
^ G 7! G ^ H=H0
^ B
Propagate
If (H ) C | B) rule with renamed fresh variables ¯x
and CT |= Gbuiltin ! 9¯x(H=H0
^ C)
then H0
^ G 7! H0
^ G ^ H=H0
^ B
Refined operational semantics [Duck+, ICLP 2004]: Similar to procedure
calls, CHR constraints evaluated depth-first from left to right and rules
applied top-down in program text order. Active vs. Partner constraint.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Properties of CHR programs
Guaranteed properties
Anytime approximation algorithm
Online incremental algorithm
Concurrent/Parallel execution
Analyzable properties
Termination/Time Complexity (semi-automatic)
Determinism/Confluence (decidable)
Program Equivalence (decidable!)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Anytime Algorithm - Approximation
Computation can be interrupted and restarted at any time.
Intermediate results approximate final result.
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Anytime Algorithm - Approximation
Computation can be interrupted and restarted at any time.
Intermediate results approximate final result.
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Anytime Algorithm - Approximation
Computation can be interrupted and restarted at any time.
Intermediate results approximate final result.
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ CA ^ AC
# (antisymmetry)
AB ^ BC ^ A=C
# (antisymmetry)
A=B ^ A=C
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Online Algorithm - Incremental
The complete input is initially unknown.
The input data arrives incrementally during computation.
No recomputation from scratch necessary.
Monotonicity and Incrementality
If G 7 ! G0
then G ^ C 7 ! G0
^ C
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ AC ^ CA
# (antisymmetry)
AB ^ BC ^ A=C
#
. . .
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Online Algorithm - Incremental
The complete input is initially unknown.
The input data arrives incrementally during computation.
No recomputation from scratch necessary.
Monotonicity and Incrementality
If G 7 ! G0
then G ^ C 7 ! G0
^ C
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ AC ^ CA
# (antisymmetry)
AB ^ BC ^ A=C
#
. . .
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Online Algorithm - Incremental
The complete input is initially unknown.
The input data arrives incrementally during computation.
No recomputation from scratch necessary.
Monotonicity and Incrementality
If G 7 ! G0
then G ^ C 7 ! G0
^ C
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ AC ^ CA
# (antisymmetry)
AB ^ BC ^ A=C
#
. . .
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Online Algorithm - Incremental
The complete input is initially unknown.
The input data arrives incrementally during computation.
No recomputation from scratch necessary.
Monotonicity and Incrementality
If G 7 ! G0
then G ^ C 7 ! G0
^ C
AB ^ BC ^ CA
# (transitivity)
AB ^ BC ^ AC ^ CA
# (antisymmetry)
AB ^ BC ^ A=C
#
. . .
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Concurrency - Strong Parallelism
Interleaving semantics: Parallel computation step can be simulated by a
sequence of sequential computation steps.
Rules can be applied in parallel to overlapping parts of a goal, if overlap
is not removed.
If A ^ E 7 ! B ^ E
and C ^ E 7 ! D ^ E
then A ^ C ^ E 7 ! B ^ D ^ E
AB ^ BC ^ CA
# #
AB ^ AC ^ BC ^ CA ^ BA
# #
A=B ^ BC ^ A=C
Thom Fr¨uhwirth Constraint Handling Rules
Concurrency - Strong Parallelism
Interleaving semantics: Parallel computation step can be simulated by a
sequence of sequential computation steps.
Rules can be applied in parallel to overlapping parts of a goal, if overlap
is not removed.
If A ^ E 7 ! B ^ E
and C ^ E 7 ! D ^ E
then A ^ C ^ E 7 ! B ^ D ^ E
AB ^ BC ^ CA
# #
AB ^ AC ^ BC ^ CA ^ BA
# #
A=B ^ BC ^ A=C
Thom Fr¨uhwirth Constraint Handling Rules
Concurrency - Strong Parallelism
Interleaving semantics: Parallel computation step can be simulated by a
sequence of sequential computation steps.
Rules can be applied in parallel to overlapping parts of a goal, if overlap
is not removed.
If A ^ E 7 ! B ^ E
and C ^ E 7 ! D ^ E
then A ^ C ^ E 7 ! B ^ D ^ E
AB ^ BC ^ CA
# #
AB ^ AC ^ BC ^ CA ^ BA
# #
A=B ^ BC ^ A=C
Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Optimal Time and Space Complexity
c
Jon Sneyers, K.U. Leuven
The CHR Machine
Sublanguage of CHR.
Can be mapped to Turing machines and
vice versa.
CHR is Turing-complete.
Can be mapped to RAM machines and
vice versa.
Every algorithm can be implemented in
CHR with best known time and space
complexity.
[Sneyers,Schrijvers,Demoen, CHR’05]
Practical Evidence: Union-Find, Shortest
Paths, Fibonacci Heap Algorithms.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
E ciency - Better Time and Space Complexity
c pixabay
- CHR with mode declarations has optimal time
and space complexity.
- JESS too, but 10-100 times slower.
- Prolog, Maude, Haskell not optimal if pure.
- CHR within one order of magnitude of best
implementations in any other language (C,. . . ).
Sneyers et.al., The computational power and complexity of Constraint Handling
Rules, ACM TOPLAS 31(2) 2009.
Thom Fr¨uhwirth Constraint Handling Rules
E ciency - The orders of magnitude
Up to one Million rules per second with CHR in C
c Van Weert
JESS, CLIPS — hours
x 10-100
JCHR 2.0, CCHR — minutes
x 10-100
CHR in FPGA Hardware — seconds
Van Weert, E cient lazy evaluation of rule-based programs, IEEE TKDE 2010.
Triossi, Compiling CHR to parallel hardware, ACM PPDP 2012.
Wuille, CCHR: the fastest CHR implementation, CHR’07.
Thom Fr¨uhwirth Constraint Handling Rules
E ciency - Superior Implementation Techniques
Faster and faster Algorithms for matching facts to rules
Eager Matching
- 1982 RETE: with join indexing.
- 1987 TREAT: without join indexing.
Lazy Matching
- 1990 LEAPS: with shadowing.
- 2000 CHR: with propagation history.
Van Weert, E cient lazy evaluation of rule-based programs, IEEE TKDE 2010.
Thom Fr¨uhwirth Constraint Handling Rules
c wikicommons
CHR Basic Compilation Scheme
r: H1,...,Hm...,Hn <=> G1,...,Gl | B1,...,Bk.
Hi is one of H1,...,Hn and the j-th occurrence in the program
procedure occurrence Hi j(Hi,IDi)
foreach (H1,ID1) in lookup(H1)
: // except Hi
foreach (Hn,IDn) in lookup(Hn)
if alive(ID1) and...and alive(IDn)
if all different(ID1,...,IDn)
if G1 and...and Gl
if not in history(r,ID1,...,IDn)
add to history(r,ID1,...,IDn);
kill(ID1);...;kill(IDm);
create(B1,IDB1);...;create(Bk,IDBk);
activate(B1,IDB1);...;activate(Bk,IDBk);
if not alive(IDi) return true
end
:
end
Thom Fr¨uhwirth Constraint Handling Rules
Common Compiler Optimizations
Fact Invariants
Set semantics
Functional Dependencies
Join Computation
Fact indexing
Backjumping
Loop-invariant code motion
Non-robust iterators
Join ordering
Fact Base
Late indexing
In-place modifications
Fact Activation
Scheduling
Passive occurrences
Retraction preference
Reapplication prevention
Program Specialization
Class specialization
Guard simplification
Thom Fr¨uhwirth Constraint Handling Rules
c wikicommons
CHR Program Analysis
Prove Program Properties
Termination
Every computation starting from any goal ends.
Semi-Automatic Complexity
Worst-case time complexity follows from structure of rules.
Consistency and Correctness
Logical reading of rules is consistent, follows from a specification.
Decidable Confluence
The answer of a query is always the same, no matter which of the
applicable rules are applied.
Completion Algorithm
Non-confluent programs made confluent by adding rules.
Decidable Operational Equivalence
Two programs have the same results for any given query.
Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Minimal States
For each rule, there is a minimal, most general state to which it is
applicable.
Rule: H , C | B or H ) C | B
Minimal State: H ^ C
Every other state to which the rule is applicable contains the minimal
state (cf. Monotonicity/Incrementality).
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Minimal States
For each rule, there is a minimal, most general state to which it is
applicable.
Rule: H , C | B or H ) C | B
Minimal State: H ^ C
Every other state to which the rule is applicable contains the minimal
state (cf. Monotonicity/Incrementality).
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Minimal States
For each rule, there is a minimal, most general state to which it is
applicable.
Rule: H , C | B or H ) C | B
Minimal State: H ^ C
Every other state to which the rule is applicable contains the minimal
state (cf. Monotonicity/Incrementality).
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Confluence
Given a goal, every computation leads to the same result no matter what
rules are applied.
A decidable, su⌅cient and necessary condition for confluence of
terminating CHR programs through joinability of critical pairs.
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
Start from overlapping minimal states
AA ^ AA
reflexivity
xxqqqqqqqqqq antisymmetry
&&MMMMMMMMMM
AA
reflexivity &&MMMMMMMMMMM A=A
built-inxxqqqqqqqqqqq
true
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Confluence
Given a goal, every computation leads to the same result no matter what
rules are applied.
A decidable, su⌅cient and necessary condition for confluence of
terminating CHR programs through joinability of critical pairs.
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
Start from overlapping minimal states
AA ^ AA
reflexivity
xxqqqqqqqqqq antisymmetry
&&MMMMMMMMMM
AA
reflexivity &&MMMMMMMMMMM A=A
built-inxxqqqqqqqqqqq
true
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Confluence
Given a goal, every computation leads to the same result no matter what
rules are applied.
A decidable, su⌅cient and necessary condition for confluence of
terminating CHR programs through joinability of critical pairs.
XX , true (reflexivity)
XY ^ Y X , X=Y (antisymmetry)
Start from overlapping minimal states
AA ^ AA
reflexivity
xxqqqqqqqqqq antisymmetry
&&MMMMMMMMMM
AA
reflexivity &&MMMMMMMMMMM A=A
built-inxxqqqqqqqqqqq
true
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Completion
Derive rules from a non-joinable critical pair for transition from one of
the critical states into the other one.
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y <X , false (inconsistency)
AB ^ BA ^ B<A
antisymmetry
zzttttttttt
inconsistency
$$IIIIIIIII
A=B ^ B<A
✏✏
BA ^ false
✏✏
A=B ^ A<A false
X<X , false (irreflexivity)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Completion
Derive rules from a non-joinable critical pair for transition from one of
the critical states into the other one.
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y <X , false (inconsistency)
AB ^ BA ^ B<A
antisymmetry
zzttttttttt
inconsistency
$$IIIIIIIII
A=B ^ B<A
✏✏
BA ^ false
✏✏
A=B ^ A<A false
X<X , false (irreflexivity)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Completion
Derive rules from a non-joinable critical pair for transition from one of
the critical states into the other one.
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y <X , false (inconsistency)
AB ^ BA ^ B<A
antisymmetry
zzttttttttt
inconsistency
$$IIIIIIIII
A=B ^ B<A
✏✏
BA ^ false
✏✏
A=B ^ A<A false
X<X , false (irreflexivity)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Completion
Derive rules from a non-joinable critical pair for transition from one of
the critical states into the other one.
XY ^ Y X , X=Y (antisymmetry)
XY ^ Y <X , false (inconsistency)
AB ^ BA ^ B<A
antisymmetry
zzttttttttt
inconsistency
$$IIIIIIIII
A=B ^ B<A
✏✏
BA ^ false
✏✏
A=B ^ A<A false
X<X , false (irreflexivity)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Operational Equivalence
Given a goal and two programs, computations in both programs leads to
the same result.
A decidable, su⌅cient and necessary condition for operational equivalence
of terminating CHR programs through joinability of minimal states.
P1 min(X, Y , Z) , XY Z=X.
min(X, Y , Z) , X>Y Z=Y .
P2 min(X, Y , Z) , X<Y Z=X.
min(X, Y , Z) , X Y Z=Y .
min(X, Y , Z) ^ XY
P1
✏✏
min(X, Y , Z) ^ XY
P2
✏✏
Z=X ^ XY
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Operational Equivalence
Given a goal and two programs, computations in both programs leads to
the same result.
A decidable, su⌅cient and necessary condition for operational equivalence
of terminating CHR programs through joinability of minimal states.
P1 min(X, Y , Z) , XY Z=X.
min(X, Y , Z) , X>Y Z=Y .
P2 min(X, Y , Z) , X<Y Z=X.
min(X, Y , Z) , X Y Z=Y .
min(X, Y , Z) ^ XY
P1
✏✏
min(X, Y , Z) ^ XY
P2
✏✏
Z=X ^ XY
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
The CHR Language
Operational Properties
Program Analysis
Operational Equivalence
Given a goal and two programs, computations in both programs leads to
the same result.
A decidable, su⌅cient and necessary condition for operational equivalence
of terminating CHR programs through joinability of minimal states.
P1 min(X, Y , Z) , XY Z=X.
min(X, Y , Z) , X>Y Z=Y .
P2 min(X, Y , Z) , X<Y Z=X.
min(X, Y , Z) , X Y Z=Y .
min(X, Y , Z) ^ XY
P1
✏✏
min(X, Y , Z) ^ XY
P2
✏✏
Z=X ^ XY
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Part II
Example Programs
4 Example Programs
5 Constraint Solvers
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Mergers and acquisitions
Sum up values:
sum(Value1), sum(Value2) <=>
sum(Value1+Value2).
Thom Fr¨uhwirth Constraint Handling Rules
Mergers and acquisitions
Sum up values:
sum(Value1), sum(Value2) <=>
sum(Value1+Value2).
CHR constraint company(Name,Value) represents company with
market value Value
Larger company buys smaller company:
company(Name1,Value1), company(Name2,Value2) <=>
Value1>Value2 | company(Name1,Value1+Value2).
Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Computational Logic Programming
fib(N,M) is true if M is the Nth Fibonacci number.
Top-down Goal-Driven Evaluation
fib(0,M) , M = 1.
fib(1,M) , M = 1.
fib(N,M) , N 2 | fib(N-1,M1) ^ fib(N-2,M2) ^ M = M1 + M2.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Computational Logic Programming
fib(N,M) is true if M is the Nth Fibonacci number.
Top-down Goal-Driven Evaluation with Tabling (Memoisation)
fib(N,M1) ^ fib(N,M2) , M1 = M2 ^ fib(N,M1).
fib(0,M) ) M = 1.
fib(1,M) ) M = 1.
fib(N,M) ) N 2 | fib(N-1,M1) ^ fib(N-2,M2) ^ M = M1 + M2.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Computational Logic Programming
fib(N,M) is true if M is the Nth Fibonacci number.
Bottom-up Data-Driven Evaluation
fib , fib(0,1) ^ fib(1,1).
fib(N1,M1) ^ fib(N2,M2) ) N1=N2+1 |
N=N1+1 ^ M=M1+M2 ^ fib(N,M).
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Computational Logic Programming
fib(N,M) is true if M is the Nth Fibonacci number.
Bottom-up Data-Driven Evaluation with Termination
fib(Max) ) fib(0,1) ^ fib(1,1).
fib(Max) ^ fib(N1,M1) ^ fib(N2,M2) ) Max>N1 ^ N1=N2+1 |
N=N1+1 ^ M=M1+M2 ^ fib(N,M).
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Computational Logic Programming
fib(N,M) is true if M is the Nth Fibonacci number.
Bottom-up Data-Driven Evaluation, Two Results Only
fib(Max) ) fib(0,1) ^ fib(1,1).
fib(Max) ^ fib(N1,M1)  fib(N2,M2) ) Max>N1 ^ N1=N2+1 |
N=N1+1 ^ M=M1+M2 ^ fib(N,M).
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Sorting
One-rule sort related to merge sort and tree sort.
Query Arc X->Ai for each unique value Ai, X only on left of arc.
Answer Ordered chain of arcs X->A1, A1->A2,...
sort @ X->A  X->B <=> A<B | A->B.
Query 0->2, 0->5, 0->1, 0->7.
Answer 0->1, 1->2, 2->5, 5->7.
Complexity: Given n values/arcs.
Each value can move O(n) times to the left.
Quadratic worst-case time complexity.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Sorting
One-rule sort related to merge sort and tree sort.
Arc 0=>Ai for each unique value Ai, left side is level (log of chain length).
sort @ X->A  X->B <=> A<B | A->B.
level@ N=>A , N=>B <=> A<B | N+1=>A, A->B.
Query 0=>2, 0=>5, 0=>1, 0=>7.
Answer 2=>1, 1->2, 2->5, 5->7.
Complexity: Optimal log-linear worst-case time complexity.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Combination of Gauss’ and Fouriers Algorithms
Gaussian Elimination for =
A1*X+P1=0 ^ XP=0 ,
find(A2*X,XP,P2)
compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3=0.
Fouriers Algorithm for
A1*X+P1 0 ^ XP 0 )
find(A2*X,XP,P2) ^ opposite_sign(A1,A2)
compute(P2-(P1/A1)*A2,P3) ^ P3 0.
Bridge Rule for = and
A1*X+P1=0 ^ XP 0 ,
find(A2*X,XP,P2)
compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3 0.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Combination of Gauss’ and Fouriers Algorithms
Gaussian Elimination for =
A1*X+P1=0 ^ XP=0 ,
find(A2*X,XP,P2)
compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3=0.
Fouriers Algorithm for
A1*X+P1 0 ^ XP 0 )
find(A2*X,XP,P2) ^ opposite_sign(A1,A2)
compute(P2-(P1/A1)*A2,P3) ^ P3 0.
Bridge Rule for = and
A1*X+P1=0 ^ XP 0 ,
find(A2*X,XP,P2)
compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3 0.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Combination of Gauss’ and Fouriers Algorithms
Gaussian Elimination for =
A1*X+P1=0 ^ XP=0 ,
find(A2*X,XP,P2)
compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3=0.
Fouriers Algorithm for
A1*X+P1 0 ^ XP 0 )
find(A2*X,XP,P2) ^ opposite_sign(A1,A2)
compute(P2-(P1/A1)*A2,P3) ^ P3 0.
Bridge Rule for = and
A1*X+P1=0 ^ XP 0 ,
find(A2*X,XP,P2)
compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3 0.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Description Logic with Rules in CHR
Straightforward integration of DL, rules and constraints.
and: If x : C1 u C2 2 A and {x : C1, x : C2} 6✓ A
then A!uA [ {x : C1, x : C2}
or: If x : C1 t C2 2 A and {x : C1, x : C2}  A = ;
then A!tA [ {x : D} for some D 2 {C1, C2}
some: If x : 9R.D 2 A and there is no y with {(x, y) : R, y : D} ✓ A
then A!9A [ {(x, y) : R, y : D} for a fresh individual y
all: If x : 8R.D 2 A and there is a y with (x, y) : R 2 A and
y : D 62 A
then A!8A [ {y : D}
Figure: The completion rules for ALC
Thom Fr¨uhwirth Constraint Handling Rules
Description Logic with Rules in CHR
Straightforward integration of DL, rules and constraints.
DL in CHR: shorter than formal specification!
Correct, confluent, concurrent, anytime, online algorithm.
and @ I:S1 and S2 <=> I:S1, I:S2
or @ I:S1 or S2 <=> (I:S1 ; I:S2)
some @ I:some R is S <=> (I,J):R, J:S
all @ I:all R is S, (I,J):R ==> J:S
Figure: CHR Rules for ALC
Thom Fr¨uhwirth Constraint Handling Rules
Description Logic with Rules in CHR
Straightforward integration of DL, rules and constraints.
DL in CHR: shorter than formal specification!
Correct, confluent, concurrent, anytime, online algorithm.
and @ I:S1 and S2 <=> I:S1, I:S2
or @ I:S1 or S2 <=> (I:S1 ; I:S2)
some @ I:some R is S <=> (I,J):R, J:S
all @ I:all R is S, (I,J):R ==> J:S
Figure: CHR Rules for ALC
Easily combine DL with CHR rules (like SWRL)
E.g. the uncle role (male sibling of person’s father):
Z:male, (Y,Z):hassibling, (X,Y):hasparent ==> (X,Z):hasuncle.
Thom Fr¨uhwirth Constraint Handling Rules
Classical Applications
Trends in Applications
Application Projects
Part III
Applications
6 Classical Applications
7 Trends in Applications
8 Application Projects
Thom Fr¨uhwirth Constraint Handling Rules
CHR Research Application Domains
- Programming type systems, algorithm design, verification and testing,
- Constraints constraint solving and reasoning,
- Time scheduling and planning, spatial and temporal reasoning,
- Logic logical reasoning, abduction, probabilistic reasoning,
- Agents agent-based systems, semantic web reasoning,
- Languages computational linguistics, grammars,
- and many more legal reasoning, cognitive system modelling, automatic
music generation, game playing, bio-informatics, data mining, . . .
Thom Fr¨uhwirth Constraint Handling Rules
Embedding Formalisms and Languages in CHR
Embedding by straightforward source-to-source transformation:
Term Rewriting Systems (TRS). Uses Equational Logic.
Functional Programming (FP),
General Abstract Model for Multiset Manipulation (GAMMA),
Graph Transformation Systems (GTS),
(Colored) Petri Nets (PN),
Logical Algorithms (LA). Only known implementation. Achieves the
tight optimal time complexity.
Production Rules and Business Rules,
Event-Condition-Action (ECA) Rules,
Deductive Database languages like DATALOG,
Description Logic (DL) with SWRL-style rules,
Prolog and Constraint Logic Programming (CLP). Uses Clark’s
Completion.
Concurrent Constraint Programming (CC) languages.
Online tool http://pmx.informatik.uni-ulm.de/chr/translator.
Thom Fr¨uhwirth Constraint Handling Rules
Logical Parallelism and Declarative Concurrency
Confluent programs can be executed in parallel
without modification.
Often optimal linear speedup by parallelization
(superlinear speedup e.g. for gcd algorithm).
Constant time sorting with CHR ultra-parallelism.
Implementations: Haskell, C++ on Nvidia CUDA,
on FPGA Hardware.
Classical Algorithms: Union-Find, Preflow-Push.
Application: Particle collider data filtering with
trigger rules at CERN.
Thom Fr¨uhwirth Constraint Handling Rules
c wikicommons
c wikicommons
Testing and Verification
Conditions, Assigments, Memory Locations modelled as CHR
constraints:
Symbolic execution along control-flow graphs
Feasible paths computation and generalisation
Automatic test data generation with heuristics
Applications
Reasoning with data structures, e.g. arrays and
heaps. Separation Logic for heap reasoning using
SMCHR (Satisfiability Modulo Theories with CHR).
Verification of business processes, agents, web
services.
Commercial Users: BSSE, Agitar, Logicblox.
BSSE found mission-critical bug in satellite
software.
Thom Fr¨uhwirth Constraint Handling Rules
c wikicommons
Probabilistic Legal Reasoning
Legal argumentation: both parties make claims and use legal rules
Judge can accept claims and rules to be
applicable or not
Given probabilities of acceptance, what is the
chance to win the case?
Expressed in Probabilistic Argumentation
Logic (a defeasible logic)
Implemented in CHRISM (CHR with PRISM
for probabilisitic reasoning and learning).
Sneyers et. al. Probabilistic legal reasoning in CHRiSM, TPLP 2013.
Thom Fr¨uhwirth Constraint Handling Rules
c wikicommons
Multimedia Transformation Engine for Web Presentations
Joost Geurts, University of Amsterdam.
Automatic generation of interactive, time-based and media centric
WWW presentations from semi-structured multimedia databases.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
c Joost Geurts
POPULAR - Planning Cordless Communication
T. Fr¨uhwirth, P. Brisset
Optimal Placement of Base Stations
in Wireless Indoor Communication
Networks, IEEE Intelligent Systems
Magazine 15(1), 2000.
Voted Among Most Innovative
Telecom Applications of the Year by
IEEE Expert Magazine, Winner of
CP98 Telecom Application Award.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
c Thom Frühwirth, Pascal Brisset
University Course Timetabling
S. Abdennadher, M. Saft, S. Will
Classroom Assignment using
Constraint Logic Programming,
PACLP 2000.
Operational at University of
Munich. Room-Allocation for
1000 Lectures a Week.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
c Slim Abdennadher
APOPCALEAPS by Jon Sneyers
!"#!$#%& '()*+,-*-./.0123*41567*8*-./.0123*957:2/*0;<*=77(:20>:5;/ %T
!"#$#%&%'()*$+(,-.
!"#$%&$'"()&*+,-#*./!"0%(/1*+*2,$%'+3!,+%4"#,$%'+
'/./*715U0U:(:/>:2*+,-*H+,V-?WJ*D51*06>5)0>:2*
)6/:2*25)75/:>:5;*E3:(.*(.01;:;C*)6/:20(*/>P(./#
Thom Fr¨uhwirth Constraint Handling Rules
Robot Sailboat by INNOC Vienna
!"#!$#%& '()*+,-*-./.0123*41567*8*-./.0123*957:2/*0;<*=77(:20>:5;/ %"
!"#$#%&%'()*$+(,-.
R5;C8>.1)*-56>:;C*D51*=6>5;5)56/*?0:(U50>/
X.*E51A*E:>3*>3.*E51(<8230)7:5;*:;*15U5>*/0:(:;C*>5*/.>*
;.E*E51(<*1.251<*:;*6;0//:/>.<*/0:(:;CY*Z(0;;:;C*:;*
25;>:;656/*<5)0:;*E:>3*6;2.1>0:;*E.0>3.1O*/.0*2611.;>/#
Foto: INNOC Vienna
Thom Fr¨uhwirth Constraint Handling Rules
Long-Term Routing using Weather and Current Forcests
Langbein, Stelzer, Fr¨uhwirth. Robotic Sailing 2011, Springer LNCS.
Thom Fr¨uhwirth Constraint Handling Rules
Industrial CHR Users
Commercial CHR Users
Stock Broking, New Zealand
Injection Mold Design, Canada
Optical Network Routing, USA
Test Case Generation, Germany
Unit Testing, USA
Knowledge Management, USA
Robotic Vehicle Control, Spain
Thom Fr¨uhwirth Constraint Handling Rules
Autonomous Vehicle Control
Thom Fr¨uhwirth Constraint Handling Rules
Financial Services
!"#!$#%& '()*+,-*-./.0123*41567*8*-./.0123*957:2/*0;<*=77(:20>:5;/ %$
!"#$#%&%'()*$+(,-.
?.261:>@0/.*?>52A8B15A:;C*?5D>E01.
! F.E*G.0(0;<*HFGIJ*
5K.1*L!M*)01A.>*/301.
! =6/>10(:0*H=?IJ*67*>5*
'?*N*&L!*):((:5;O*
L!O!!!*>10<./*7.1*<0P
! +,-*6/.<*D51*06>5)0>:2*
>10<:;CO*51<.1*
022.7>0;2.*23.2A.1O*
D51)/*25)7:(.1O*?QR*
S6.1P*25)7:(.1
Thom Fr¨uhwirth Constraint Handling Rules
c wikicommons
Constraint Handling Rules
Ultra-high-level formalism and programming language
Integrated into host languages like Prolog, Java, C...
Dozens of open-source implementations
Naturally supports parallelism
Online and anytime algorithm properties for free
Analysis tools (termination, complexity, confluence)
Faster than commercial rule-based systems
Lingua Franca for Computation
Thom Fr¨uhwirth Constraint Handling Rules
CHR Logo
Getting Started with Constraint Handling Rules
Search the Internet/Web for ”Constraint Handling Rules”
Play with CHR at
http://chrjs.net/
Thom Fr¨uhwirth Constraint Handling Rules
MAKE YOUR OWN RULES.
CONSTRAINT HANDLING RULES
Finally...
Google “Constraint Handling Rules” for the CHR website
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Supplementary Material
Finally...
Google “Constraint Handling Rules” for the CHR website
Transcribed as CHR, means
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Finally...
Google “Constraint Handling Rules” for the CHR website
Transcribed as CHR, means
to speed, to propagate, to be famous
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Chemical Abstract Machine Style
One constraint. One Simpagation rule.
min(N)  min(M) , N=<M | true.
gcd(N)  gcd(M) , 0<N,N=<M | gcd(M-N).
fib(N)  fib(M) , 0<N,M=<N | fib(M+N).
prime(I)  prime(J) , J mod I = 0 | true.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Chemical Abstract Machine Style
One constraint. One Simpagation rule.
min(N)  min(M) , N=<M | true.
gcd(N)  gcd(M) , 0<N,N=<M | gcd(M-N).
fib(N)  fib(M) , 0<N,M=<N | fib(M+N).
prime(I)  prime(J) , J mod I = 0 | true.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Chemical Abstract Machine Style
One constraint. One Simpagation rule.
min(N)  min(M) , N=<M | true.
gcd(N)  gcd(M) , 0<N,N=<M | gcd(M-N).
fib(N)  fib(M) , 0<N,M=<N | fib(M+N).
prime(I)  prime(J) , J mod I = 0 | true.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Chemical Abstract Machine Style
One constraint. One Simpagation rule.
min(N)  min(M) , N=<M | true.
gcd(N)  gcd(M) , 0<N,N=<M | gcd(M-N).
fib(N)  fib(M) , 0<N,M=<N | fib(M+N).
prime(I)  prime(J) , J mod I = 0 | true.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Paths in a Graph
e(X, Y ) ) p(X, Y ).
e(X, Z) ^ p(Z, Y ) ) p(X, Y ).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d)
##
e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Paths in a Graph
e(X, Y ) ) p(X, Y ).
e(X, Z) ^ p(Z, Y ) ) p(X, Y ).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d)
##
e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Paths in a Graph
e(X, Y ) ) p(X, Y ).
e(X, Z) ^ p(Z, Y ) ) p(X, Y ).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d)
##
e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Paths in a Graph
e(X, Y ) ) p(X, Y ).
e(X, Z) ^ p(Z, Y ) ) p(X, Y ).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d)
##
e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Paths in a Graph
e(X, Y ) ) p(X, Y ).
e(X, Z) ^ p(Z, Y ) ) p(X, Y ).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d)
##
e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Paths in a Graph
e(X, Y ) ) p(X, Y ).
e(X, Z) ^ p(Z, Y ) ) p(X, Y ).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d)
##
e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Paths in a Graph
e(X, Y ) ) p(X, Y ).
e(X, Z) ^ p(Z, Y ) ) p(X, Y ).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d)
##
e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Paths in a Graph
e(X, Y ) ) p(X, Y ).
e(X, Z) ^ p(Z, Y ) ) p(X, Y ).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d)
##
e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Shortest Paths in a Graph
p(X, Y , N)  p(X, Y , M) , NM | true.
e(X, Y ) ) p(X, Y , 1).
e(X, Z) ^ p(Z, Y , N) ) p(X, Y , N+1).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b, 1) ^ p(b, c, 1) ^ p(c, d, 1)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Shortest Paths in a Graph
p(X, Y , N)  p(X, Y , M) , NM | true.
e(X, Y ) ) p(X, Y , 1).
e(X, Z) ^ p(Z, Y , N) ) p(X, Y , N+1).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b, 1) ^ p(b, c, 1) ^ p(c, d, 1)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Shortest Paths in a Graph
p(X, Y , N)  p(X, Y , M) , NM | true.
e(X, Y ) ) p(X, Y , 1).
e(X, Z) ^ p(Z, Y , N) ) p(X, Y , N+1).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b, 1) ^ p(b, c, 1) ^ p(c, d, 1)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Shortest Paths in a Graph
p(X, Y , N)  p(X, Y , M) , NM | true.
e(X, Y ) ) p(X, Y , 1).
e(X, Z) ^ p(Z, Y , N) ) p(X, Y , N+1).
e(a, b) ^ e(b, c) ^ e(c, d)
##
e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b, 1) ^ p(b, c, 1) ^ p(c, d, 1)
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Page 32 My first CHR programs | Multiset transformation | Exchange sort
Exchange sort (I)
Exchange sort program
a(I,V), a(J,W) <=> I>J, V<W | a(I,W), a(J,V).
I Rule sorts array by exchanging values which are in wrong order
I Array is sequence of constraints a(Index,Value
i.e. a(1, A1),...,a(n,An)
Example computation
a(0,1), a(1,7), a(2,5), a(3,9), a(4,2)
a(0,1), a(1,5), a(2,7), a(3,2), a(4,9)
a(0,1), a(1,5), a(2,2), a(3,7), a(4,9)
a(0,1), a(1,2), a(2,5), a(3,7), a(4,9)
)
Example Programs
Constraint Solvers
Linear Polynomial Equations
Equations of the form a1x1 + . . . + anxn + b = 0.
Solved form: leftmost variable occurs only once.
Reach solved normal form by Gaussian-style variable elimination.
A1*X+P1=0 ^ XP=0 ,
find(A2*X,XP,P2)
compute(P2-(P1/A1)*A2,P3) ^
A1*X+P1=0 ^ P3=0.
B=0 , number(B) zero(B).
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
Example Programs
Constraint Solvers
Fourier’s Algorithm
A1*X+P1 0 ^ XP 0 )
find(A2*X,XP,P2) ^ opposite_sign(A1,A2)
compute(P2-(P1/A1)*A2,P3) ^
P3 0.
B 0 , number(B) non_negative(B).
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
MRA - The Munich Rent Advisor
T. Fr¨uhwirth,
S. Abdennadher
The Munich Rent Advisor,
Journal of Theory and
Practice of Logic
Programming, 2000.
Most Popular
Constraint-Based Internet
Application.
Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules

More Related Content

What's hot

A Graph Syntax for Processes and Services @ Workshop WS-FM 2009
A Graph Syntax for Processes and Services @ Workshop WS-FM 2009A Graph Syntax for Processes and Services @ Workshop WS-FM 2009
A Graph Syntax for Processes and Services @ Workshop WS-FM 2009
Alberto Lluch Lafuente
 
Bag of Pursuits and Neural Gas for Improved Sparse Codin
Bag of Pursuits and Neural Gas for Improved Sparse CodinBag of Pursuits and Neural Gas for Improved Sparse Codin
Bag of Pursuits and Neural Gas for Improved Sparse Codin
Karlos Svoboda
 
Multilayer Neural Networks
Multilayer Neural NetworksMultilayer Neural Networks
Multilayer Neural Networks
ESCOM
 
Transportation and assignment_problem
Transportation and assignment_problemTransportation and assignment_problem
Transportation and assignment_problem
Ankit Katiyar
 

What's hot (20)

Volume and edge skeleton computation in high dimensions
Volume and edge skeleton computation in high dimensionsVolume and edge skeleton computation in high dimensions
Volume and edge skeleton computation in high dimensions
 
A Graph Syntax for Processes and Services @ Workshop WS-FM 2009
A Graph Syntax for Processes and Services @ Workshop WS-FM 2009A Graph Syntax for Processes and Services @ Workshop WS-FM 2009
A Graph Syntax for Processes and Services @ Workshop WS-FM 2009
 
[AAAI-16] Tiebreaking Strategies for A* Search: How to Explore the Final Fron...
[AAAI-16] Tiebreaking Strategies for A* Search: How to Explore the Final Fron...[AAAI-16] Tiebreaking Strategies for A* Search: How to Explore the Final Fron...
[AAAI-16] Tiebreaking Strategies for A* Search: How to Explore the Final Fron...
 
Towards Dynamic Updates in Service Composition - Prof. Mario Bravetti
Towards Dynamic Updates in Service Composition - Prof. Mario BravettiTowards Dynamic Updates in Service Composition - Prof. Mario Bravetti
Towards Dynamic Updates in Service Composition - Prof. Mario Bravetti
 
Modification of a heuristic method
Modification of a heuristic methodModification of a heuristic method
Modification of a heuristic method
 
Bag of Pursuits and Neural Gas for Improved Sparse Codin
Bag of Pursuits and Neural Gas for Improved Sparse CodinBag of Pursuits and Neural Gas for Improved Sparse Codin
Bag of Pursuits and Neural Gas for Improved Sparse Codin
 
Presentation of volesti in eRum 2020
Presentation of volesti in eRum 2020 Presentation of volesti in eRum 2020
Presentation of volesti in eRum 2020
 
14th Athens Colloquium on Algorithms and Complexity (ACAC19)
14th Athens Colloquium on Algorithms and Complexity (ACAC19)14th Athens Colloquium on Algorithms and Complexity (ACAC19)
14th Athens Colloquium on Algorithms and Complexity (ACAC19)
 
Probabilistic Retrieval TFIDF
Probabilistic Retrieval TFIDFProbabilistic Retrieval TFIDF
Probabilistic Retrieval TFIDF
 
20320140501020
2032014050102020320140501020
20320140501020
 
Selected topics in Bayesian Optimization
Selected topics in Bayesian OptimizationSelected topics in Bayesian Optimization
Selected topics in Bayesian Optimization
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 
Colloquium presentation
Colloquium presentationColloquium presentation
Colloquium presentation
 
Fulltext
FulltextFulltext
Fulltext
 
"On the Bayesian Interpretation of Black–Litterman" by Dr. Gordon Ritter, Sen...
"On the Bayesian Interpretation of Black–Litterman" by Dr. Gordon Ritter, Sen..."On the Bayesian Interpretation of Black–Litterman" by Dr. Gordon Ritter, Sen...
"On the Bayesian Interpretation of Black–Litterman" by Dr. Gordon Ritter, Sen...
 
Sensors and Samples: A Homological Approach
Sensors and Samples:  A Homological ApproachSensors and Samples:  A Homological Approach
Sensors and Samples: A Homological Approach
 
Multilayer Neural Networks
Multilayer Neural NetworksMultilayer Neural Networks
Multilayer Neural Networks
 
Transportation and assignment_problem
Transportation and assignment_problemTransportation and assignment_problem
Transportation and assignment_problem
 
Understanding distributed calculi in Haskell
Understanding distributed calculi in HaskellUnderstanding distributed calculi in Haskell
Understanding distributed calculi in Haskell
 
Lec5 advanced-policy-gradient-methods
Lec5 advanced-policy-gradient-methodsLec5 advanced-policy-gradient-methods
Lec5 advanced-policy-gradient-methods
 

Similar to RuleML 2015 Constraint Handling Rules - What Else?

Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Silvio Cesare
 
Poggi analytics - star - 1a
Poggi   analytics - star - 1aPoggi   analytics - star - 1a
Poggi analytics - star - 1a
Gaston Liberman
 
RedisConf18 - CRDTs and Redis - From sequential to concurrent executions
RedisConf18 - CRDTs and Redis - From sequential to concurrent executionsRedisConf18 - CRDTs and Redis - From sequential to concurrent executions
RedisConf18 - CRDTs and Redis - From sequential to concurrent executions
Redis Labs
 

Similar to RuleML 2015 Constraint Handling Rules - What Else? (20)

Coordinate sampler: A non-reversible Gibbs-like sampler
Coordinate sampler: A non-reversible Gibbs-like samplerCoordinate sampler: A non-reversible Gibbs-like sampler
Coordinate sampler: A non-reversible Gibbs-like sampler
 
Coordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like samplerCoordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like sampler
 
2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster
 
The Concurrent Constraint Programming Research Programmes -- Redux (part2)
The Concurrent Constraint Programming Research Programmes -- Redux (part2)The Concurrent Constraint Programming Research Programmes -- Redux (part2)
The Concurrent Constraint Programming Research Programmes -- Redux (part2)
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
 
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
 
Prpagation of Error Bounds Across reduction interfaces
Prpagation of Error Bounds Across reduction interfacesPrpagation of Error Bounds Across reduction interfaces
Prpagation of Error Bounds Across reduction interfaces
 
AbdoSummerANS_mod3
AbdoSummerANS_mod3AbdoSummerANS_mod3
AbdoSummerANS_mod3
 
defense
defensedefense
defense
 
Research internship on optimal stochastic theory with financial application u...
Research internship on optimal stochastic theory with financial application u...Research internship on optimal stochastic theory with financial application u...
Research internship on optimal stochastic theory with financial application u...
 
Presentation on stochastic control problem with financial applications (Merto...
Presentation on stochastic control problem with financial applications (Merto...Presentation on stochastic control problem with financial applications (Merto...
Presentation on stochastic control problem with financial applications (Merto...
 
Scalable trust-region method for deep reinforcement learning using Kronecker-...
Scalable trust-region method for deep reinforcement learning using Kronecker-...Scalable trust-region method for deep reinforcement learning using Kronecker-...
Scalable trust-region method for deep reinforcement learning using Kronecker-...
 
Poggi analytics - star - 1a
Poggi   analytics - star - 1aPoggi   analytics - star - 1a
Poggi analytics - star - 1a
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculus
 
Q-Metrics in Theory and Practice
Q-Metrics in Theory and PracticeQ-Metrics in Theory and Practice
Q-Metrics in Theory and Practice
 
Q-Metrics in Theory And Practice
Q-Metrics in Theory And PracticeQ-Metrics in Theory And Practice
Q-Metrics in Theory And Practice
 
RedisConf18 - CRDTs and Redis - From sequential to concurrent executions
RedisConf18 - CRDTs and Redis - From sequential to concurrent executionsRedisConf18 - CRDTs and Redis - From sequential to concurrent executions
RedisConf18 - CRDTs and Redis - From sequential to concurrent executions
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 

More from RuleML

A software agent controlling 2 robot arms in co-operating concurrent tasks
A software agent controlling 2 robot arms in co-operating concurrent tasksA software agent controlling 2 robot arms in co-operating concurrent tasks
A software agent controlling 2 robot arms in co-operating concurrent tasks
RuleML
 

More from RuleML (20)

Aggregates in Recursion: Issues and Solutions
Aggregates in Recursion: Issues and SolutionsAggregates in Recursion: Issues and Solutions
Aggregates in Recursion: Issues and Solutions
 
A software agent controlling 2 robot arms in co-operating concurrent tasks
A software agent controlling 2 robot arms in co-operating concurrent tasksA software agent controlling 2 robot arms in co-operating concurrent tasks
A software agent controlling 2 robot arms in co-operating concurrent tasks
 
Port Clearance Rules in PSOA RuleML: From Controlled-English Regulation to Ob...
Port Clearance Rules in PSOA RuleML: From Controlled-English Regulation to Ob...Port Clearance Rules in PSOA RuleML: From Controlled-English Regulation to Ob...
Port Clearance Rules in PSOA RuleML: From Controlled-English Regulation to Ob...
 
RuleML 2015: When Processes Rule Events
RuleML 2015: When Processes Rule EventsRuleML 2015: When Processes Rule Events
RuleML 2015: When Processes Rule Events
 
RuleML 2015: Ontology Reasoning using Rules in an eHealth Context
RuleML 2015: Ontology Reasoning using Rules in an eHealth ContextRuleML 2015: Ontology Reasoning using Rules in an eHealth Context
RuleML 2015: Ontology Reasoning using Rules in an eHealth Context
 
RuleML 2015: Semantics of Notation3 Logic: A Solution for Implicit Quantifica...
RuleML 2015: Semantics of Notation3 Logic: A Solution for Implicit Quantifica...RuleML 2015: Semantics of Notation3 Logic: A Solution for Implicit Quantifica...
RuleML 2015: Semantics of Notation3 Logic: A Solution for Implicit Quantifica...
 
Challenge@RuleML2015 Developing Situation-Aware Applications for Disaster Man...
Challenge@RuleML2015 Developing Situation-Aware Applications for Disaster Man...Challenge@RuleML2015 Developing Situation-Aware Applications for Disaster Man...
Challenge@RuleML2015 Developing Situation-Aware Applications for Disaster Man...
 
Rule Generalization Strategies in Incremental Learning of Disjunctive Concepts
Rule Generalization Strategies in Incremental Learning of Disjunctive ConceptsRule Generalization Strategies in Incremental Learning of Disjunctive Concepts
Rule Generalization Strategies in Incremental Learning of Disjunctive Concepts
 
RuleML2015 The Herbrand Manifesto - Thinking Inside the Box
RuleML2015 The Herbrand Manifesto - Thinking Inside the Box RuleML2015 The Herbrand Manifesto - Thinking Inside the Box
RuleML2015 The Herbrand Manifesto - Thinking Inside the Box
 
RuleML2015 PSOA RuleML: Integrated Object-Relational Data and Rules
RuleML2015 PSOA RuleML: Integrated Object-Relational Data and RulesRuleML2015 PSOA RuleML: Integrated Object-Relational Data and Rules
RuleML2015 PSOA RuleML: Integrated Object-Relational Data and Rules
 
Industry@RuleML2015: Norwegian State of Estate A Reporting Service for the St...
Industry@RuleML2015: Norwegian State of Estate A Reporting Service for the St...Industry@RuleML2015: Norwegian State of Estate A Reporting Service for the St...
Industry@RuleML2015: Norwegian State of Estate A Reporting Service for the St...
 
A Service for Improving the Assignments of Common Agriculture Policy Funds to...
A Service for Improving the Assignments of Common Agriculture Policy Funds to...A Service for Improving the Assignments of Common Agriculture Policy Funds to...
A Service for Improving the Assignments of Common Agriculture Policy Funds to...
 
Datalog+-Track Introduction & Reasoning on UML Class Diagrams via Datalog+-
Datalog+-Track Introduction & Reasoning on UML Class Diagrams via Datalog+-Datalog+-Track Introduction & Reasoning on UML Class Diagrams via Datalog+-
Datalog+-Track Introduction & Reasoning on UML Class Diagrams via Datalog+-
 
RuleML2015: Binary Frontier-guarded ASP with Function Symbols
RuleML2015: Binary Frontier-guarded ASP with Function SymbolsRuleML2015: Binary Frontier-guarded ASP with Function Symbols
RuleML2015: Binary Frontier-guarded ASP with Function Symbols
 
RuleML2015: API4KP Metamodel: A Meta-API for Heterogeneous Knowledge Platforms
RuleML2015: API4KP Metamodel: A Meta-API for Heterogeneous Knowledge PlatformsRuleML2015: API4KP Metamodel: A Meta-API for Heterogeneous Knowledge Platforms
RuleML2015: API4KP Metamodel: A Meta-API for Heterogeneous Knowledge Platforms
 
RuleML2015: Rule-Based Exploration of Structured Data in the Browser
RuleML2015: Rule-Based Exploration of Structured Data in the BrowserRuleML2015: Rule-Based Exploration of Structured Data in the Browser
RuleML2015: Rule-Based Exploration of Structured Data in the Browser
 
RuleML2015: Ontology-Based Multidimensional Contexts with Applications to Qua...
RuleML2015: Ontology-Based Multidimensional Contexts with Applications to Qua...RuleML2015: Ontology-Based Multidimensional Contexts with Applications to Qua...
RuleML2015: Ontology-Based Multidimensional Contexts with Applications to Qua...
 
RuleML2015: Compact representation of conditional probability for rule-based...
RuleML2015:  Compact representation of conditional probability for rule-based...RuleML2015:  Compact representation of conditional probability for rule-based...
RuleML2015: Compact representation of conditional probability for rule-based...
 
RuleML2015: Learning Characteristic Rules in Geographic Information Systems
RuleML2015: Learning Characteristic Rules in Geographic Information SystemsRuleML2015: Learning Characteristic Rules in Geographic Information Systems
RuleML2015: Learning Characteristic Rules in Geographic Information Systems
 
RuleML2015: Using Substitutive Itemset Mining Framework for Finding Synonymou...
RuleML2015: Using Substitutive Itemset Mining Framework for Finding Synonymou...RuleML2015: Using Substitutive Itemset Mining Framework for Finding Synonymou...
RuleML2015: Using Substitutive Itemset Mining Framework for Finding Synonymou...
 

Recently uploaded

Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Sérgio Sacani
 
Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
levieagacer
 

Recently uploaded (20)

pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit flypumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICESAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate ProfessorThyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
 
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
chemical bonding Essentials of Physical Chemistry2.pdf
chemical bonding Essentials of Physical Chemistry2.pdfchemical bonding Essentials of Physical Chemistry2.pdf
chemical bonding Essentials of Physical Chemistry2.pdf
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
 
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 

RuleML 2015 Constraint Handling Rules - What Else?

  • 1. Constraint Handling Rules - What Else? Thom Fr¨uhwirth University of Ulm, Germany Thom Fr¨uhwirth Constraint Handling Rules
  • 2. What Researchers Say About CHR One of the most powerful multiset rewriting languages. Kazunori Ueda, Waseda University, Japan Consistently outperforms Rete-based rule-based systems. Peter Van Weert, K.U. Leuven Significant speed up when executed on multi-core systems. Edmund S. L. Lam, National University of Singapore Lingua franca, a hub which collects and dispenses research e↵orts from and to the various related fields. Jon Sneyers, K.U. Leuven Thom Fr¨uhwirth Constraint Handling Rules
  • 3. Page 9 My first CHR programs | Multiset transformation | Minimum Minimum I Minimum program min(N) min(M) <=> N=<M | true. I Computing minimum of multiset of numbers ni I Numbers given as query min(n1), min(n2),..., min(nk) I min(ni) means ni is potential minimum I Simpagation rule takes two min constraints and removes the one representing the larger value. I Program continues until only one min constraint left I This min constraint represents smallest value
  • 4. Page 10 My first CHR programs | Multiset transformation | Minimum Minimum II Minimum program min(N) min(M) <=> N=<M | true. I Rule corresponds to intuitive algorithm: “Cross out larger numbers until one, the minimum remains” I Illustrates use of multi-headed rule to iterate over data I No explicit loops or recursion needed I Keeps program code compact I Makes program easier to analyze
  • 5. Page 24 My first CHR programs | Multiset transformation | Greatest common divisor Greatest common divisor (I) XOR program gcd(N) gcd(M) <=> 0<N,N=<M | gcd(M-N). I Computes greatest common divisor of natural number represented as gcd(N) I Result is remaining nonzero gcd constraint Example computation gcd(12),gcd(8) gcd(8), gcd(4) gcd(4), gcd(4) gcd(4), gcd(0) GCD
  • 6. Page 29 My first CHR programs | Multiset transformation | Prime number Sieve of Eratosthenes Prime sieve Prime sieve (I) sift @ prime(I) prime(J) <=> J mod I =:= 0 | true. I Rule removes multiples of each of the numbers I Query: Prime number candidates from 2 to up to N i.e. prime(2),prime(3),prime(4),...prime(N) I Each number absorbs multiples of itself, eventually only prime numbers remain Example computation prime(7), prime(6), prime(5), prime(4), prime(3), prime(2) prime(7), prime(5), prime(4), prime(3), prime(2) prime(7), prime(5), prime(3), prime(2)
  • 7. Constraint Handling Rules (CHR) Concurrent declarative programming language and versatile computational formalism as well Semantic foundation in classical and linear logic E cient sequential and parallel execution model Guaranteed properties such as anytime and online algorithm properties Powerful analysis methods for deciding e.g. program equivalence Thom Fr¨uhwirth Constraint Handling Rules
  • 8. The CHR Language Operational Properties Program Analysis Part I The CHR Language 1 The CHR Language 2 Operational Properties 3 Program Analysis Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 9. The CHR Language Operational Properties Program Analysis Example Partial Order Constraint XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) XY ^ Y Z ) XZ (transitivity) AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C || [built-in solver] AB ^ BA ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 10. The CHR Language Operational Properties Program Analysis Example Partial Order Constraint XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) XY ^ Y Z ) XZ (transitivity) AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C || [built-in solver] AB ^ BA ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 11. The CHR Language Operational Properties Program Analysis Example Partial Order Constraint XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) XY ^ Y Z ) XZ (transitivity) AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C || [built-in solver] AB ^ BA ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 12. The CHR Language Operational Properties Program Analysis Example Partial Order Constraint XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) XY ^ Y Z ) XZ (transitivity) AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C || [built-in solver] AB ^ BA ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 13. The CHR Language Operational Properties Program Analysis Example Partial Order Constraint XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) XY ^ Y Z ) XZ (transitivity) AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C || [built-in solver] AB ^ BA ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 14. The CHR Language Operational Properties Program Analysis Example Partial Order Constraint XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) XY ^ Y Z ) XZ (transitivity) AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C || [built-in solver] AB ^ BA ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 15. The CHR Language Operational Properties Program Analysis Example Partial Order Constraint XY , X=Y | true (reflexivity) XY ^ Y X , X=Y (antisymmetry) XY ^ Y Z ) XZ (transitivity) AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C || [built-in solver] AB ^ BA ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 16. The CHR Language Operational Properties Program Analysis Syntax and Declarative Semantics Declarative Semantics Simplification rule: H , C | B 8¯x (C ! (H $ 9¯y B)) Propagation rule: H ) C | B 8¯x (C ! (H ! 9¯y B)) Constraint Theory for Built-Ins Head H: non-empty conjunction of CHR constraints Guard C: conjunction of built-in constraints Body B: conjunction of CHR and built-in constraints (goal) Soundness and Completeness based on logical equivalence of states in a computation. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 17. The CHR Language Operational Properties Program Analysis Operational Semantics Apply rules until exhaustion in any order (fixpoint computation). Initial goal (query) 7!⇤ result (answer). Simplify If (H , C | B) rule with renamed fresh variables ¯x and CT |= Gbuiltin ! 9¯x(H=H0 ^ C) then H0 ^ G 7! G ^ H=H0 ^ B Propagate If (H ) C | B) rule with renamed fresh variables ¯x and CT |= Gbuiltin ! 9¯x(H=H0 ^ C) then H0 ^ G 7! H0 ^ G ^ H=H0 ^ B Refined operational semantics [Duck+, ICLP 2004]: Similar to procedure calls, CHR constraints evaluated depth-first from left to right and rules applied top-down in program text order. Active vs. Partner constraint. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 18. The CHR Language Operational Properties Program Analysis Operational Semantics Apply rules until exhaustion in any order (fixpoint computation). Initial goal (query) 7!⇤ result (answer). Simplify If (H , C | B) rule with renamed fresh variables ¯x and CT |= Gbuiltin ! 9¯x(H=H0 ^ C) then H0 ^ G 7! G ^ H=H0 ^ B Propagate If (H ) C | B) rule with renamed fresh variables ¯x and CT |= Gbuiltin ! 9¯x(H=H0 ^ C) then H0 ^ G 7! H0 ^ G ^ H=H0 ^ B Refined operational semantics [Duck+, ICLP 2004]: Similar to procedure calls, CHR constraints evaluated depth-first from left to right and rules applied top-down in program text order. Active vs. Partner constraint. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 19. The CHR Language Operational Properties Program Analysis Operational Semantics Apply rules until exhaustion in any order (fixpoint computation). Initial goal (query) 7!⇤ result (answer). Simplify If (H , C | B) rule with renamed fresh variables ¯x and CT |= Gbuiltin ! 9¯x(H=H0 ^ C) then H0 ^ G 7! G ^ H=H0 ^ B Propagate If (H ) C | B) rule with renamed fresh variables ¯x and CT |= Gbuiltin ! 9¯x(H=H0 ^ C) then H0 ^ G 7! H0 ^ G ^ H=H0 ^ B Refined operational semantics [Duck+, ICLP 2004]: Similar to procedure calls, CHR constraints evaluated depth-first from left to right and rules applied top-down in program text order. Active vs. Partner constraint. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 20. The CHR Language Operational Properties Program Analysis Operational Semantics Apply rules until exhaustion in any order (fixpoint computation). Initial goal (query) 7!⇤ result (answer). Simplify If (H , C | B) rule with renamed fresh variables ¯x and CT |= Gbuiltin ! 9¯x(H=H0 ^ C) then H0 ^ G 7! G ^ H=H0 ^ B Propagate If (H ) C | B) rule with renamed fresh variables ¯x and CT |= Gbuiltin ! 9¯x(H=H0 ^ C) then H0 ^ G 7! H0 ^ G ^ H=H0 ^ B Refined operational semantics [Duck+, ICLP 2004]: Similar to procedure calls, CHR constraints evaluated depth-first from left to right and rules applied top-down in program text order. Active vs. Partner constraint. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 21. Properties of CHR programs Guaranteed properties Anytime approximation algorithm Online incremental algorithm Concurrent/Parallel execution Analyzable properties Termination/Time Complexity (semi-automatic) Determinism/Confluence (decidable) Program Equivalence (decidable!) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 22. The CHR Language Operational Properties Program Analysis Anytime Algorithm - Approximation Computation can be interrupted and restarted at any time. Intermediate results approximate final result. AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 23. The CHR Language Operational Properties Program Analysis Anytime Algorithm - Approximation Computation can be interrupted and restarted at any time. Intermediate results approximate final result. AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 24. The CHR Language Operational Properties Program Analysis Anytime Algorithm - Approximation Computation can be interrupted and restarted at any time. Intermediate results approximate final result. AB ^ BC ^ CA # (transitivity) AB ^ BC ^ CA ^ AC # (antisymmetry) AB ^ BC ^ A=C # (antisymmetry) A=B ^ A=C Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 25. The CHR Language Operational Properties Program Analysis Online Algorithm - Incremental The complete input is initially unknown. The input data arrives incrementally during computation. No recomputation from scratch necessary. Monotonicity and Incrementality If G 7 ! G0 then G ^ C 7 ! G0 ^ C AB ^ BC ^ CA # (transitivity) AB ^ BC ^ AC ^ CA # (antisymmetry) AB ^ BC ^ A=C # . . . Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 26. The CHR Language Operational Properties Program Analysis Online Algorithm - Incremental The complete input is initially unknown. The input data arrives incrementally during computation. No recomputation from scratch necessary. Monotonicity and Incrementality If G 7 ! G0 then G ^ C 7 ! G0 ^ C AB ^ BC ^ CA # (transitivity) AB ^ BC ^ AC ^ CA # (antisymmetry) AB ^ BC ^ A=C # . . . Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 27. The CHR Language Operational Properties Program Analysis Online Algorithm - Incremental The complete input is initially unknown. The input data arrives incrementally during computation. No recomputation from scratch necessary. Monotonicity and Incrementality If G 7 ! G0 then G ^ C 7 ! G0 ^ C AB ^ BC ^ CA # (transitivity) AB ^ BC ^ AC ^ CA # (antisymmetry) AB ^ BC ^ A=C # . . . Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 28. The CHR Language Operational Properties Program Analysis Online Algorithm - Incremental The complete input is initially unknown. The input data arrives incrementally during computation. No recomputation from scratch necessary. Monotonicity and Incrementality If G 7 ! G0 then G ^ C 7 ! G0 ^ C AB ^ BC ^ CA # (transitivity) AB ^ BC ^ AC ^ CA # (antisymmetry) AB ^ BC ^ A=C # . . . Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 29. Concurrency - Strong Parallelism Interleaving semantics: Parallel computation step can be simulated by a sequence of sequential computation steps. Rules can be applied in parallel to overlapping parts of a goal, if overlap is not removed. If A ^ E 7 ! B ^ E and C ^ E 7 ! D ^ E then A ^ C ^ E 7 ! B ^ D ^ E AB ^ BC ^ CA # # AB ^ AC ^ BC ^ CA ^ BA # # A=B ^ BC ^ A=C Thom Fr¨uhwirth Constraint Handling Rules
  • 30. Concurrency - Strong Parallelism Interleaving semantics: Parallel computation step can be simulated by a sequence of sequential computation steps. Rules can be applied in parallel to overlapping parts of a goal, if overlap is not removed. If A ^ E 7 ! B ^ E and C ^ E 7 ! D ^ E then A ^ C ^ E 7 ! B ^ D ^ E AB ^ BC ^ CA # # AB ^ AC ^ BC ^ CA ^ BA # # A=B ^ BC ^ A=C Thom Fr¨uhwirth Constraint Handling Rules
  • 31. Concurrency - Strong Parallelism Interleaving semantics: Parallel computation step can be simulated by a sequence of sequential computation steps. Rules can be applied in parallel to overlapping parts of a goal, if overlap is not removed. If A ^ E 7 ! B ^ E and C ^ E 7 ! D ^ E then A ^ C ^ E 7 ! B ^ D ^ E AB ^ BC ^ CA # # AB ^ AC ^ BC ^ CA ^ BA # # A=B ^ BC ^ A=C Thom Fr¨uhwirth Constraint Handling Rules
  • 32. The CHR Language Operational Properties Program Analysis Optimal Time and Space Complexity c Jon Sneyers, K.U. Leuven The CHR Machine Sublanguage of CHR. Can be mapped to Turing machines and vice versa. CHR is Turing-complete. Can be mapped to RAM machines and vice versa. Every algorithm can be implemented in CHR with best known time and space complexity. [Sneyers,Schrijvers,Demoen, CHR’05] Practical Evidence: Union-Find, Shortest Paths, Fibonacci Heap Algorithms. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 33. E ciency - Better Time and Space Complexity c pixabay - CHR with mode declarations has optimal time and space complexity. - JESS too, but 10-100 times slower. - Prolog, Maude, Haskell not optimal if pure. - CHR within one order of magnitude of best implementations in any other language (C,. . . ). Sneyers et.al., The computational power and complexity of Constraint Handling Rules, ACM TOPLAS 31(2) 2009. Thom Fr¨uhwirth Constraint Handling Rules
  • 34. E ciency - The orders of magnitude Up to one Million rules per second with CHR in C c Van Weert JESS, CLIPS — hours x 10-100 JCHR 2.0, CCHR — minutes x 10-100 CHR in FPGA Hardware — seconds Van Weert, E cient lazy evaluation of rule-based programs, IEEE TKDE 2010. Triossi, Compiling CHR to parallel hardware, ACM PPDP 2012. Wuille, CCHR: the fastest CHR implementation, CHR’07. Thom Fr¨uhwirth Constraint Handling Rules
  • 35. E ciency - Superior Implementation Techniques Faster and faster Algorithms for matching facts to rules Eager Matching - 1982 RETE: with join indexing. - 1987 TREAT: without join indexing. Lazy Matching - 1990 LEAPS: with shadowing. - 2000 CHR: with propagation history. Van Weert, E cient lazy evaluation of rule-based programs, IEEE TKDE 2010. Thom Fr¨uhwirth Constraint Handling Rules c wikicommons
  • 36. CHR Basic Compilation Scheme r: H1,...,Hm...,Hn <=> G1,...,Gl | B1,...,Bk. Hi is one of H1,...,Hn and the j-th occurrence in the program procedure occurrence Hi j(Hi,IDi) foreach (H1,ID1) in lookup(H1) : // except Hi foreach (Hn,IDn) in lookup(Hn) if alive(ID1) and...and alive(IDn) if all different(ID1,...,IDn) if G1 and...and Gl if not in history(r,ID1,...,IDn) add to history(r,ID1,...,IDn); kill(ID1);...;kill(IDm); create(B1,IDB1);...;create(Bk,IDBk); activate(B1,IDB1);...;activate(Bk,IDBk); if not alive(IDi) return true end : end Thom Fr¨uhwirth Constraint Handling Rules
  • 37. Common Compiler Optimizations Fact Invariants Set semantics Functional Dependencies Join Computation Fact indexing Backjumping Loop-invariant code motion Non-robust iterators Join ordering Fact Base Late indexing In-place modifications Fact Activation Scheduling Passive occurrences Retraction preference Reapplication prevention Program Specialization Class specialization Guard simplification Thom Fr¨uhwirth Constraint Handling Rules c wikicommons
  • 38. CHR Program Analysis Prove Program Properties Termination Every computation starting from any goal ends. Semi-Automatic Complexity Worst-case time complexity follows from structure of rules. Consistency and Correctness Logical reading of rules is consistent, follows from a specification. Decidable Confluence The answer of a query is always the same, no matter which of the applicable rules are applied. Completion Algorithm Non-confluent programs made confluent by adding rules. Decidable Operational Equivalence Two programs have the same results for any given query. Thom Fr¨uhwirth Constraint Handling Rules
  • 39. The CHR Language Operational Properties Program Analysis Minimal States For each rule, there is a minimal, most general state to which it is applicable. Rule: H , C | B or H ) C | B Minimal State: H ^ C Every other state to which the rule is applicable contains the minimal state (cf. Monotonicity/Incrementality). Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 40. The CHR Language Operational Properties Program Analysis Minimal States For each rule, there is a minimal, most general state to which it is applicable. Rule: H , C | B or H ) C | B Minimal State: H ^ C Every other state to which the rule is applicable contains the minimal state (cf. Monotonicity/Incrementality). Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 41. The CHR Language Operational Properties Program Analysis Minimal States For each rule, there is a minimal, most general state to which it is applicable. Rule: H , C | B or H ) C | B Minimal State: H ^ C Every other state to which the rule is applicable contains the minimal state (cf. Monotonicity/Incrementality). Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 42. The CHR Language Operational Properties Program Analysis Confluence Given a goal, every computation leads to the same result no matter what rules are applied. A decidable, su⌅cient and necessary condition for confluence of terminating CHR programs through joinability of critical pairs. XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) Start from overlapping minimal states AA ^ AA reflexivity xxqqqqqqqqqq antisymmetry &&MMMMMMMMMM AA reflexivity &&MMMMMMMMMMM A=A built-inxxqqqqqqqqqqq true Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 43. The CHR Language Operational Properties Program Analysis Confluence Given a goal, every computation leads to the same result no matter what rules are applied. A decidable, su⌅cient and necessary condition for confluence of terminating CHR programs through joinability of critical pairs. XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) Start from overlapping minimal states AA ^ AA reflexivity xxqqqqqqqqqq antisymmetry &&MMMMMMMMMM AA reflexivity &&MMMMMMMMMMM A=A built-inxxqqqqqqqqqqq true Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 44. The CHR Language Operational Properties Program Analysis Confluence Given a goal, every computation leads to the same result no matter what rules are applied. A decidable, su⌅cient and necessary condition for confluence of terminating CHR programs through joinability of critical pairs. XX , true (reflexivity) XY ^ Y X , X=Y (antisymmetry) Start from overlapping minimal states AA ^ AA reflexivity xxqqqqqqqqqq antisymmetry &&MMMMMMMMMM AA reflexivity &&MMMMMMMMMMM A=A built-inxxqqqqqqqqqqq true Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 45. The CHR Language Operational Properties Program Analysis Completion Derive rules from a non-joinable critical pair for transition from one of the critical states into the other one. XY ^ Y X , X=Y (antisymmetry) XY ^ Y <X , false (inconsistency) AB ^ BA ^ B<A antisymmetry zzttttttttt inconsistency $$IIIIIIIII A=B ^ B<A ✏✏ BA ^ false ✏✏ A=B ^ A<A false X<X , false (irreflexivity) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 46. The CHR Language Operational Properties Program Analysis Completion Derive rules from a non-joinable critical pair for transition from one of the critical states into the other one. XY ^ Y X , X=Y (antisymmetry) XY ^ Y <X , false (inconsistency) AB ^ BA ^ B<A antisymmetry zzttttttttt inconsistency $$IIIIIIIII A=B ^ B<A ✏✏ BA ^ false ✏✏ A=B ^ A<A false X<X , false (irreflexivity) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 47. The CHR Language Operational Properties Program Analysis Completion Derive rules from a non-joinable critical pair for transition from one of the critical states into the other one. XY ^ Y X , X=Y (antisymmetry) XY ^ Y <X , false (inconsistency) AB ^ BA ^ B<A antisymmetry zzttttttttt inconsistency $$IIIIIIIII A=B ^ B<A ✏✏ BA ^ false ✏✏ A=B ^ A<A false X<X , false (irreflexivity) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 48. The CHR Language Operational Properties Program Analysis Completion Derive rules from a non-joinable critical pair for transition from one of the critical states into the other one. XY ^ Y X , X=Y (antisymmetry) XY ^ Y <X , false (inconsistency) AB ^ BA ^ B<A antisymmetry zzttttttttt inconsistency $$IIIIIIIII A=B ^ B<A ✏✏ BA ^ false ✏✏ A=B ^ A<A false X<X , false (irreflexivity) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 49. The CHR Language Operational Properties Program Analysis Operational Equivalence Given a goal and two programs, computations in both programs leads to the same result. A decidable, su⌅cient and necessary condition for operational equivalence of terminating CHR programs through joinability of minimal states. P1 min(X, Y , Z) , XY Z=X. min(X, Y , Z) , X>Y Z=Y . P2 min(X, Y , Z) , X<Y Z=X. min(X, Y , Z) , X Y Z=Y . min(X, Y , Z) ^ XY P1 ✏✏ min(X, Y , Z) ^ XY P2 ✏✏ Z=X ^ XY Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 50. The CHR Language Operational Properties Program Analysis Operational Equivalence Given a goal and two programs, computations in both programs leads to the same result. A decidable, su⌅cient and necessary condition for operational equivalence of terminating CHR programs through joinability of minimal states. P1 min(X, Y , Z) , XY Z=X. min(X, Y , Z) , X>Y Z=Y . P2 min(X, Y , Z) , X<Y Z=X. min(X, Y , Z) , X Y Z=Y . min(X, Y , Z) ^ XY P1 ✏✏ min(X, Y , Z) ^ XY P2 ✏✏ Z=X ^ XY Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 51. The CHR Language Operational Properties Program Analysis Operational Equivalence Given a goal and two programs, computations in both programs leads to the same result. A decidable, su⌅cient and necessary condition for operational equivalence of terminating CHR programs through joinability of minimal states. P1 min(X, Y , Z) , XY Z=X. min(X, Y , Z) , X>Y Z=Y . P2 min(X, Y , Z) , X<Y Z=X. min(X, Y , Z) , X Y Z=Y . min(X, Y , Z) ^ XY P1 ✏✏ min(X, Y , Z) ^ XY P2 ✏✏ Z=X ^ XY Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 52. Example Programs Constraint Solvers Part II Example Programs 4 Example Programs 5 Constraint Solvers Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 53. Mergers and acquisitions Sum up values: sum(Value1), sum(Value2) <=> sum(Value1+Value2). Thom Fr¨uhwirth Constraint Handling Rules
  • 54. Mergers and acquisitions Sum up values: sum(Value1), sum(Value2) <=> sum(Value1+Value2). CHR constraint company(Name,Value) represents company with market value Value Larger company buys smaller company: company(Name1,Value1), company(Name2,Value2) <=> Value1>Value2 | company(Name1,Value1+Value2). Thom Fr¨uhwirth Constraint Handling Rules
  • 55. Example Programs Constraint Solvers Computational Logic Programming fib(N,M) is true if M is the Nth Fibonacci number. Top-down Goal-Driven Evaluation fib(0,M) , M = 1. fib(1,M) , M = 1. fib(N,M) , N 2 | fib(N-1,M1) ^ fib(N-2,M2) ^ M = M1 + M2. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 56. Example Programs Constraint Solvers Computational Logic Programming fib(N,M) is true if M is the Nth Fibonacci number. Top-down Goal-Driven Evaluation with Tabling (Memoisation) fib(N,M1) ^ fib(N,M2) , M1 = M2 ^ fib(N,M1). fib(0,M) ) M = 1. fib(1,M) ) M = 1. fib(N,M) ) N 2 | fib(N-1,M1) ^ fib(N-2,M2) ^ M = M1 + M2. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 57. Example Programs Constraint Solvers Computational Logic Programming fib(N,M) is true if M is the Nth Fibonacci number. Bottom-up Data-Driven Evaluation fib , fib(0,1) ^ fib(1,1). fib(N1,M1) ^ fib(N2,M2) ) N1=N2+1 | N=N1+1 ^ M=M1+M2 ^ fib(N,M). Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 58. Example Programs Constraint Solvers Computational Logic Programming fib(N,M) is true if M is the Nth Fibonacci number. Bottom-up Data-Driven Evaluation with Termination fib(Max) ) fib(0,1) ^ fib(1,1). fib(Max) ^ fib(N1,M1) ^ fib(N2,M2) ) Max>N1 ^ N1=N2+1 | N=N1+1 ^ M=M1+M2 ^ fib(N,M). Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 59. Example Programs Constraint Solvers Computational Logic Programming fib(N,M) is true if M is the Nth Fibonacci number. Bottom-up Data-Driven Evaluation, Two Results Only fib(Max) ) fib(0,1) ^ fib(1,1). fib(Max) ^ fib(N1,M1) fib(N2,M2) ) Max>N1 ^ N1=N2+1 | N=N1+1 ^ M=M1+M2 ^ fib(N,M). Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 60. Example Programs Constraint Solvers Sorting One-rule sort related to merge sort and tree sort. Query Arc X->Ai for each unique value Ai, X only on left of arc. Answer Ordered chain of arcs X->A1, A1->A2,... sort @ X->A X->B <=> A<B | A->B. Query 0->2, 0->5, 0->1, 0->7. Answer 0->1, 1->2, 2->5, 5->7. Complexity: Given n values/arcs. Each value can move O(n) times to the left. Quadratic worst-case time complexity. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 61. Example Programs Constraint Solvers Sorting One-rule sort related to merge sort and tree sort. Arc 0=>Ai for each unique value Ai, left side is level (log of chain length). sort @ X->A X->B <=> A<B | A->B. level@ N=>A , N=>B <=> A<B | N+1=>A, A->B. Query 0=>2, 0=>5, 0=>1, 0=>7. Answer 2=>1, 1->2, 2->5, 5->7. Complexity: Optimal log-linear worst-case time complexity. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 62. Example Programs Constraint Solvers Combination of Gauss’ and Fouriers Algorithms Gaussian Elimination for = A1*X+P1=0 ^ XP=0 , find(A2*X,XP,P2) compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3=0. Fouriers Algorithm for A1*X+P1 0 ^ XP 0 ) find(A2*X,XP,P2) ^ opposite_sign(A1,A2) compute(P2-(P1/A1)*A2,P3) ^ P3 0. Bridge Rule for = and A1*X+P1=0 ^ XP 0 , find(A2*X,XP,P2) compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3 0. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 63. Example Programs Constraint Solvers Combination of Gauss’ and Fouriers Algorithms Gaussian Elimination for = A1*X+P1=0 ^ XP=0 , find(A2*X,XP,P2) compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3=0. Fouriers Algorithm for A1*X+P1 0 ^ XP 0 ) find(A2*X,XP,P2) ^ opposite_sign(A1,A2) compute(P2-(P1/A1)*A2,P3) ^ P3 0. Bridge Rule for = and A1*X+P1=0 ^ XP 0 , find(A2*X,XP,P2) compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3 0. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 64. Example Programs Constraint Solvers Combination of Gauss’ and Fouriers Algorithms Gaussian Elimination for = A1*X+P1=0 ^ XP=0 , find(A2*X,XP,P2) compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3=0. Fouriers Algorithm for A1*X+P1 0 ^ XP 0 ) find(A2*X,XP,P2) ^ opposite_sign(A1,A2) compute(P2-(P1/A1)*A2,P3) ^ P3 0. Bridge Rule for = and A1*X+P1=0 ^ XP 0 , find(A2*X,XP,P2) compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3 0. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 65. Description Logic with Rules in CHR Straightforward integration of DL, rules and constraints. and: If x : C1 u C2 2 A and {x : C1, x : C2} 6✓ A then A!uA [ {x : C1, x : C2} or: If x : C1 t C2 2 A and {x : C1, x : C2} A = ; then A!tA [ {x : D} for some D 2 {C1, C2} some: If x : 9R.D 2 A and there is no y with {(x, y) : R, y : D} ✓ A then A!9A [ {(x, y) : R, y : D} for a fresh individual y all: If x : 8R.D 2 A and there is a y with (x, y) : R 2 A and y : D 62 A then A!8A [ {y : D} Figure: The completion rules for ALC Thom Fr¨uhwirth Constraint Handling Rules
  • 66. Description Logic with Rules in CHR Straightforward integration of DL, rules and constraints. DL in CHR: shorter than formal specification! Correct, confluent, concurrent, anytime, online algorithm. and @ I:S1 and S2 <=> I:S1, I:S2 or @ I:S1 or S2 <=> (I:S1 ; I:S2) some @ I:some R is S <=> (I,J):R, J:S all @ I:all R is S, (I,J):R ==> J:S Figure: CHR Rules for ALC Thom Fr¨uhwirth Constraint Handling Rules
  • 67. Description Logic with Rules in CHR Straightforward integration of DL, rules and constraints. DL in CHR: shorter than formal specification! Correct, confluent, concurrent, anytime, online algorithm. and @ I:S1 and S2 <=> I:S1, I:S2 or @ I:S1 or S2 <=> (I:S1 ; I:S2) some @ I:some R is S <=> (I,J):R, J:S all @ I:all R is S, (I,J):R ==> J:S Figure: CHR Rules for ALC Easily combine DL with CHR rules (like SWRL) E.g. the uncle role (male sibling of person’s father): Z:male, (Y,Z):hassibling, (X,Y):hasparent ==> (X,Z):hasuncle. Thom Fr¨uhwirth Constraint Handling Rules
  • 68. Classical Applications Trends in Applications Application Projects Part III Applications 6 Classical Applications 7 Trends in Applications 8 Application Projects Thom Fr¨uhwirth Constraint Handling Rules
  • 69. CHR Research Application Domains - Programming type systems, algorithm design, verification and testing, - Constraints constraint solving and reasoning, - Time scheduling and planning, spatial and temporal reasoning, - Logic logical reasoning, abduction, probabilistic reasoning, - Agents agent-based systems, semantic web reasoning, - Languages computational linguistics, grammars, - and many more legal reasoning, cognitive system modelling, automatic music generation, game playing, bio-informatics, data mining, . . . Thom Fr¨uhwirth Constraint Handling Rules
  • 70. Embedding Formalisms and Languages in CHR Embedding by straightforward source-to-source transformation: Term Rewriting Systems (TRS). Uses Equational Logic. Functional Programming (FP), General Abstract Model for Multiset Manipulation (GAMMA), Graph Transformation Systems (GTS), (Colored) Petri Nets (PN), Logical Algorithms (LA). Only known implementation. Achieves the tight optimal time complexity. Production Rules and Business Rules, Event-Condition-Action (ECA) Rules, Deductive Database languages like DATALOG, Description Logic (DL) with SWRL-style rules, Prolog and Constraint Logic Programming (CLP). Uses Clark’s Completion. Concurrent Constraint Programming (CC) languages. Online tool http://pmx.informatik.uni-ulm.de/chr/translator. Thom Fr¨uhwirth Constraint Handling Rules
  • 71. Logical Parallelism and Declarative Concurrency Confluent programs can be executed in parallel without modification. Often optimal linear speedup by parallelization (superlinear speedup e.g. for gcd algorithm). Constant time sorting with CHR ultra-parallelism. Implementations: Haskell, C++ on Nvidia CUDA, on FPGA Hardware. Classical Algorithms: Union-Find, Preflow-Push. Application: Particle collider data filtering with trigger rules at CERN. Thom Fr¨uhwirth Constraint Handling Rules c wikicommons c wikicommons
  • 72. Testing and Verification Conditions, Assigments, Memory Locations modelled as CHR constraints: Symbolic execution along control-flow graphs Feasible paths computation and generalisation Automatic test data generation with heuristics Applications Reasoning with data structures, e.g. arrays and heaps. Separation Logic for heap reasoning using SMCHR (Satisfiability Modulo Theories with CHR). Verification of business processes, agents, web services. Commercial Users: BSSE, Agitar, Logicblox. BSSE found mission-critical bug in satellite software. Thom Fr¨uhwirth Constraint Handling Rules c wikicommons
  • 73. Probabilistic Legal Reasoning Legal argumentation: both parties make claims and use legal rules Judge can accept claims and rules to be applicable or not Given probabilities of acceptance, what is the chance to win the case? Expressed in Probabilistic Argumentation Logic (a defeasible logic) Implemented in CHRISM (CHR with PRISM for probabilisitic reasoning and learning). Sneyers et. al. Probabilistic legal reasoning in CHRiSM, TPLP 2013. Thom Fr¨uhwirth Constraint Handling Rules c wikicommons
  • 74. Multimedia Transformation Engine for Web Presentations Joost Geurts, University of Amsterdam. Automatic generation of interactive, time-based and media centric WWW presentations from semi-structured multimedia databases. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules c Joost Geurts
  • 75. POPULAR - Planning Cordless Communication T. Fr¨uhwirth, P. Brisset Optimal Placement of Base Stations in Wireless Indoor Communication Networks, IEEE Intelligent Systems Magazine 15(1), 2000. Voted Among Most Innovative Telecom Applications of the Year by IEEE Expert Magazine, Winner of CP98 Telecom Application Award. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules c Thom Frühwirth, Pascal Brisset
  • 76. University Course Timetabling S. Abdennadher, M. Saft, S. Will Classroom Assignment using Constraint Logic Programming, PACLP 2000. Operational at University of Munich. Room-Allocation for 1000 Lectures a Week. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules c Slim Abdennadher
  • 77. APOPCALEAPS by Jon Sneyers !"#!$#%& '()*+,-*-./.0123*41567*8*-./.0123*957:2/*0;<*=77(:20>:5;/ %T !"#$#%&%'()*$+(,-. !"#$%&$'"()&*+,-#*./!"0%(/1*+*2,$%'+3!,+%4"#,$%'+ '/./*715U0U:(:/>:2*+,-*H+,V-?WJ*D51*06>5)0>:2* )6/:2*25)75/:>:5;*E3:(.*(.01;:;C*)6/:20(*/>P(./# Thom Fr¨uhwirth Constraint Handling Rules
  • 78. Robot Sailboat by INNOC Vienna !"#!$#%& '()*+,-*-./.0123*41567*8*-./.0123*957:2/*0;<*=77(:20>:5;/ %" !"#$#%&%'()*$+(,-. R5;C8>.1)*-56>:;C*D51*=6>5;5)56/*?0:(U50>/ X.*E51A*E:>3*>3.*E51(<8230)7:5;*:;*15U5>*/0:(:;C*>5*/.>* ;.E*E51(<*1.251<*:;*6;0//:/>.<*/0:(:;CY*Z(0;;:;C*:;* 25;>:;656/*<5)0:;*E:>3*6;2.1>0:;*E.0>3.1O*/.0*2611.;>/# Foto: INNOC Vienna Thom Fr¨uhwirth Constraint Handling Rules
  • 79. Long-Term Routing using Weather and Current Forcests Langbein, Stelzer, Fr¨uhwirth. Robotic Sailing 2011, Springer LNCS. Thom Fr¨uhwirth Constraint Handling Rules
  • 80. Industrial CHR Users Commercial CHR Users Stock Broking, New Zealand Injection Mold Design, Canada Optical Network Routing, USA Test Case Generation, Germany Unit Testing, USA Knowledge Management, USA Robotic Vehicle Control, Spain Thom Fr¨uhwirth Constraint Handling Rules
  • 81. Autonomous Vehicle Control Thom Fr¨uhwirth Constraint Handling Rules
  • 82. Financial Services !"#!$#%& '()*+,-*-./.0123*41567*8*-./.0123*957:2/*0;<*=77(:20>:5;/ %$ !"#$#%&%'()*$+(,-. ?.261:>@0/.*?>52A8B15A:;C*?5D>E01. ! F.E*G.0(0;<*HFGIJ* 5K.1*L!M*)01A.>*/301. ! =6/>10(:0*H=?IJ*67*>5* '?*N*&L!*):((:5;O* L!O!!!*>10<./*7.1*<0P ! +,-*6/.<*D51*06>5)0>:2* >10<:;CO*51<.1* 022.7>0;2.*23.2A.1O* D51)/*25)7:(.1O*?QR* S6.1P*25)7:(.1 Thom Fr¨uhwirth Constraint Handling Rules c wikicommons
  • 83. Constraint Handling Rules Ultra-high-level formalism and programming language Integrated into host languages like Prolog, Java, C... Dozens of open-source implementations Naturally supports parallelism Online and anytime algorithm properties for free Analysis tools (termination, complexity, confluence) Faster than commercial rule-based systems Lingua Franca for Computation Thom Fr¨uhwirth Constraint Handling Rules CHR Logo
  • 84. Getting Started with Constraint Handling Rules Search the Internet/Web for ”Constraint Handling Rules” Play with CHR at http://chrjs.net/ Thom Fr¨uhwirth Constraint Handling Rules
  • 85. MAKE YOUR OWN RULES. CONSTRAINT HANDLING RULES
  • 86. Finally... Google “Constraint Handling Rules” for the CHR website Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules Supplementary Material
  • 87. Finally... Google “Constraint Handling Rules” for the CHR website Transcribed as CHR, means Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 88. Finally... Google “Constraint Handling Rules” for the CHR website Transcribed as CHR, means to speed, to propagate, to be famous Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 89. Example Programs Constraint Solvers Chemical Abstract Machine Style One constraint. One Simpagation rule. min(N) min(M) , N=<M | true. gcd(N) gcd(M) , 0<N,N=<M | gcd(M-N). fib(N) fib(M) , 0<N,M=<N | fib(M+N). prime(I) prime(J) , J mod I = 0 | true. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 90. Example Programs Constraint Solvers Chemical Abstract Machine Style One constraint. One Simpagation rule. min(N) min(M) , N=<M | true. gcd(N) gcd(M) , 0<N,N=<M | gcd(M-N). fib(N) fib(M) , 0<N,M=<N | fib(M+N). prime(I) prime(J) , J mod I = 0 | true. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 91. Example Programs Constraint Solvers Chemical Abstract Machine Style One constraint. One Simpagation rule. min(N) min(M) , N=<M | true. gcd(N) gcd(M) , 0<N,N=<M | gcd(M-N). fib(N) fib(M) , 0<N,M=<N | fib(M+N). prime(I) prime(J) , J mod I = 0 | true. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 92. Example Programs Constraint Solvers Chemical Abstract Machine Style One constraint. One Simpagation rule. min(N) min(M) , N=<M | true. gcd(N) gcd(M) , 0<N,N=<M | gcd(M-N). fib(N) fib(M) , 0<N,M=<N | fib(M+N). prime(I) prime(J) , J mod I = 0 | true. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 93. Example Programs Constraint Solvers Paths in a Graph e(X, Y ) ) p(X, Y ). e(X, Z) ^ p(Z, Y ) ) p(X, Y ). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d) ## e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 94. Example Programs Constraint Solvers Paths in a Graph e(X, Y ) ) p(X, Y ). e(X, Z) ^ p(Z, Y ) ) p(X, Y ). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d) ## e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 95. Example Programs Constraint Solvers Paths in a Graph e(X, Y ) ) p(X, Y ). e(X, Z) ^ p(Z, Y ) ) p(X, Y ). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d) ## e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 96. Example Programs Constraint Solvers Paths in a Graph e(X, Y ) ) p(X, Y ). e(X, Z) ^ p(Z, Y ) ) p(X, Y ). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d) ## e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 97. Example Programs Constraint Solvers Paths in a Graph e(X, Y ) ) p(X, Y ). e(X, Z) ^ p(Z, Y ) ) p(X, Y ). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d) ## e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 98. Example Programs Constraint Solvers Paths in a Graph e(X, Y ) ) p(X, Y ). e(X, Z) ^ p(Z, Y ) ) p(X, Y ). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d) ## e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 99. Example Programs Constraint Solvers Paths in a Graph e(X, Y ) ) p(X, Y ). e(X, Z) ^ p(Z, Y ) ) p(X, Y ). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d) ## e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 100. Example Programs Constraint Solvers Paths in a Graph e(X, Y ) ) p(X, Y ). e(X, Z) ^ p(Z, Y ) ) p(X, Y ). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b) ^ p(b, c) ^ p(c, d) ^ p(a, c) ^ p(b, d) ## e(a, b)^e(b, c)^e(c, d)^p(a, b)^p(b, c)^p(c, d)^p(a, c)^p(b, d)^p(a, d) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 101. Example Programs Constraint Solvers Shortest Paths in a Graph p(X, Y , N) p(X, Y , M) , NM | true. e(X, Y ) ) p(X, Y , 1). e(X, Z) ^ p(Z, Y , N) ) p(X, Y , N+1). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b, 1) ^ p(b, c, 1) ^ p(c, d, 1) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 102. Example Programs Constraint Solvers Shortest Paths in a Graph p(X, Y , N) p(X, Y , M) , NM | true. e(X, Y ) ) p(X, Y , 1). e(X, Z) ^ p(Z, Y , N) ) p(X, Y , N+1). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b, 1) ^ p(b, c, 1) ^ p(c, d, 1) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 103. Example Programs Constraint Solvers Shortest Paths in a Graph p(X, Y , N) p(X, Y , M) , NM | true. e(X, Y ) ) p(X, Y , 1). e(X, Z) ^ p(Z, Y , N) ) p(X, Y , N+1). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b, 1) ^ p(b, c, 1) ^ p(c, d, 1) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 104. Example Programs Constraint Solvers Shortest Paths in a Graph p(X, Y , N) p(X, Y , M) , NM | true. e(X, Y ) ) p(X, Y , 1). e(X, Z) ^ p(Z, Y , N) ) p(X, Y , N+1). e(a, b) ^ e(b, c) ^ e(c, d) ## e(a, b) ^ e(b, c) ^ e(c, d) ^ p(a, b, 1) ^ p(b, c, 1) ^ p(c, d, 1) Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 105. Page 32 My first CHR programs | Multiset transformation | Exchange sort Exchange sort (I) Exchange sort program a(I,V), a(J,W) <=> I>J, V<W | a(I,W), a(J,V). I Rule sorts array by exchanging values which are in wrong order I Array is sequence of constraints a(Index,Value i.e. a(1, A1),...,a(n,An) Example computation a(0,1), a(1,7), a(2,5), a(3,9), a(4,2) a(0,1), a(1,5), a(2,7), a(3,2), a(4,9) a(0,1), a(1,5), a(2,2), a(3,7), a(4,9) a(0,1), a(1,2), a(2,5), a(3,7), a(4,9) )
  • 106. Example Programs Constraint Solvers Linear Polynomial Equations Equations of the form a1x1 + . . . + anxn + b = 0. Solved form: leftmost variable occurs only once. Reach solved normal form by Gaussian-style variable elimination. A1*X+P1=0 ^ XP=0 , find(A2*X,XP,P2) compute(P2-(P1/A1)*A2,P3) ^ A1*X+P1=0 ^ P3=0. B=0 , number(B) zero(B). Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 107. Example Programs Constraint Solvers Fourier’s Algorithm A1*X+P1 0 ^ XP 0 ) find(A2*X,XP,P2) ^ opposite_sign(A1,A2) compute(P2-(P1/A1)*A2,P3) ^ P3 0. B 0 , number(B) non_negative(B). Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules
  • 108. MRA - The Munich Rent Advisor T. Fr¨uhwirth, S. Abdennadher The Munich Rent Advisor, Journal of Theory and Practice of Logic Programming, 2000. Most Popular Constraint-Based Internet Application. Prof. Dr. Thom Fr¨uhwirth Constraint Handling Rules