:- use_module(library(chr)). :- chr_constraint state/3. /********** testqueries fulladder(1,1,1,1,1). fulladder(1,0,1,1,1), fulladder(1,1,1,0,0), fulladder(0,0,0,0,1). THis one is fine: fulladder(1,0,1,1,1), fulladder(1,1,1,0,0),write(*),fail. 64 solutions Correct + wrong - overlap fulladder(1,1,1,1,1), fulladder(1,1,1,1,0), write(*),fail. Correct + wrong - no overlap fulladder(1,1,1,1,1), fulladder(1,0,0,1,0), write(*),fail. 64 solutions Another: 3 correct and three wrong. fulladder(0,1,1,1,0), fulladder(0,1,0,0,1), fulladder(0,0,1,0,1), fulladder(1,0,1,1,1), fulladder(1,1,1,0,0), fulladder(0,0,0,0,1), write(*),fail. 262144 ******************/ fulladder(Carryin, A, B, Carryout, Sum):- xor(A, B, X, g1), and(A, B, Y, g2), and(X, Carryin, Z, g3), xor(Carryin, X, Sum, g4), or(Y, Z, Carryout, g5). disturbe(0,1). disturbe(1,0). not(0, 1). not(1, 0). and(0, 0, 0). and(0, 1, 0). and(1, 0, 0). and(1, 1, 1). xor(0, 0, 0). xor(0, 1, 1). xor(1, 0, 1). xor(1, 1, 0). or(0, 0, 0). or(0, 1, 1). or(1, 0, 1). or(1, 1, 1). not(A,X,Id):- not(A,X), state(Id,A,ok). not(A,X,Id):- not(A,Z), disturbe(Z,X), state(Id,A,ko). and(A,B,X,Id):- and(A,B,X), state(Id,A+B,ok). and(A,B,X,Id):- and(A,B,Z), disturbe(Z,X), state(Id,A+B,ko). or(A,B,X,Id):- or(A,B,X), state(Id,A+B,ok). or(A,B,X,Id):- or(A,B,Z), disturbe(Z,X), state(Id,A+B,ko). xor(A,B,X,Id):- xor(A,B,X), state(Id,A+B,ok). xor(A,B,X,Id):- xor(A,B,Z), disturbe(Z,X), state(Id,A+B,ko).