Previous Up

15.7  Propia and CHR Exercise

The problem is to implement three constraints, and, or and xor in CHRs and, as a separate exercise, in Propia. The constraints are specified as follows: All boolean variables have domain {0,1}: 0 for ’false’ and 1 for ’true’.

and(X,Y,Z) =def (X & Y) = Z
or(X,Y,Z) =def (X or Y) = Z
xor(X,Y,Z) =def ((X & -Y) or (-X & Y)) = Z

Suppose your constraints are called cons_and, cons_or and cons_xor Now write enter the following procedure:

full_adder(I1,I2,I3,O1,O2) :-
    cons_xor(I1,I2,X1),
    cons_and(I1,I2,Y1),
    cons_xor(X1,I3,O1),
    cons_and(I3,X1,Y2),
    cons_or(Y1,Y2,O2).

The problem is solved if you enter the query:

?- full_adder(I1,I2,0,O1,1).

and get the correct answer.

Note: you are not allowed to load the ic library nor to use search and backtracking!


Previous Up