__Simpagation Rules__

Simpagation in Constraint Handling Rules (CHR) have the following format:

Where Head 1 and Head 2 are two separate lists of constraints. A simpagation rule is similar to a simplification rule,

except that only the constraints in Head 2 are discarded, while the constraints in Head 1 are preserved.

Simpagation rules could be rewritten to simplification rules as follows :

As we can see, simpagation rules make the writing of rules much simpler, by eliminating repetition of constraints.

Our next task is to write a program that can find the largest number in a list of numbers. The program can look as follows:

Head 1 \ Head 2 <=> Guard | Body.Head 1 \ Head 2 <=> Guard | Body.

Where Head 1 and Head 2 are two separate lists of constraints. A simpagation rule is similar to a simplification rule,

except that only the constraints in Head 2 are discarded, while the constraints in Head 1 are preserved.

Simpagation rules could be rewritten to simplification rules as follows :

*Head 1, Head 2 <=> Guard | Head 1, Body.*As we can see, simpagation rules make the writing of rules much simpler, by eliminating repetition of constraints.

Our next task is to write a program that can find the largest number in a list of numbers. The program can look as follows:

largest_number ( Numbers ) :- %1 maplist ( number_chr , %2 Numbers ). %3 number_chr (A) \ number_chr (B) <=> %4 A >= B | true . %5

The rule that is in line 5 is a simpagation rule that compares two numbers, A and B. If A is larger than or equal to B,

then the second constraint

a

then the second constraint

*number_chr(B)*is replaced with true, i.e., discarded. Line 1 is a Prolog predicate that postsa

*number_chr/1*constraint for each number in the list. An example query is presented below.?- largest_number ([1 ,0 ,3 ,8 ,112 , -22 ,55 ,89]). number_chr (112) true .

As we can see, whenever the simpagation rule fires, two constraints containing two numbers in the list are compared,

and the constraint that contains the smaller number is discarded. This goes on until only one number CHR remains,

which contains the largest number in the list. Note that the order of posting the constraints does not affect the final

result. For example, if the constraints with the numbers 3 and 8 are posted in that order, CHR would try to satisfy the

rule by changing the positions of the constraints, making 8 as variable A, and 3 as variable B.

and the constraint that contains the smaller number is discarded. This goes on until only one number CHR remains,

which contains the largest number in the list. Note that the order of posting the constraints does not affect the final

result. For example, if the constraints with the numbers 3 and 8 are posted in that order, CHR would try to satisfy the

rule by changing the positions of the constraints, making 8 as variable A, and 3 as variable B.