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) :-

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