:- use_module( library(chr)). :- chr_constraint boolean/1, and/3, or/3, xor/3, neg/2, imp/2, equiv/3. chr_option(check_guard_bindings, off). chr_option(already_in_heads, off). chr_option(debug_compile,on). boolean(0) <=> true. boolean(1) <=> true. % and/3 specification %and(0,0,0). %and(0,1,0). %and(1,0,0). %and(1,1,1). and(0,_,Y) <=> Y=0. and(_,0,Y) <=> Y=0. and(1,X,Y) <=> Y=X. and(X,1,Y) <=> Y=X. and(X,Y,1) <=> X=1,Y=1. and(X,X,Z) <=> X=Z. and(X,Y,A) \ and(X,Y,B) <=> A=B. and(X,Y,A) \ and(Y,X,B) <=> A=B. % or/3 specification %or(0,0,0). %or(0,1,1). %or(1,0,1). %or(1,1,1). or(0,X,Y) <=> Y=X. or(X,0,Y) <=> Y=X. or(X,Y,0) <=> X=0,Y=0. or(1,_,Y) <=> Y=1. or(_,1,Y) <=> Y=1. or(X,X,Z) <=> X=Z. %or(X,Y,X) <=> imp(Y,X). %or(X,Y,Y) <=> imp(X,Y). or(X,Y,A) \ or(X,Y,B) <=> A=B. or(X,Y,A) \ or(Y,X,B) <=> A=B. imp(0,_) <=> true. imp(X,0) <=> X=0. imp(1,X) <=> X=1. imp(_,1) <=> true. imp(X,X) <=> true. imp(X,Y),imp(Y,X) <=> X=Y. % xor/3 specification %xor(0,0,0). %xor(0,1,1). %xor(1,0,1). %xor(1,1,0). xor(0,X,Y) <=> X=Y. xor(X,0,Y) <=> X=Y. xor(X,Y,0) <=> X=Y. xor(1,X,Y) <=> neg(X,Y). xor(X,1,Y) <=> neg(X,Y). xor(X,Y,1) <=> neg(X,Y). xor(X,X,Y) <=> Y=0. xor(X,Y,X) <=> Y=0. xor(Y,X,X) <=> Y=0. xor(X,Y,A) \ xor(X,Y,B) <=> A=B. xor(X,Y,A) \ xor(Y,X,B) <=> A=B. % neg/2 specification %neg(0,1). %neg(1,0). neg(0,X) <=> X=1. neg(X,0) <=> X=1. neg(1,X) <=> X=0. neg(X,1) <=> X=0. neg(X,X) <=> fail. neg_neg @ neg(X,Y) \ neg(Y,Z) <=> X=Z. neg_neg @ neg(X,Y) \ neg(Z,Y) <=> X=Z. neg_neg @ neg(Y,X) \ neg(Y,Z) <=> X=Z. % Interaction with other boolean constraints neg(X,Y) \ and(X,Y,Z) <=> Z=0. neg(Y,X) \ and(X,Y,Z) <=> Z=0. neg(X,Z) , and(X,Y,Z) <=> X=1,Y=0,Z=0. neg(Z,X) , and(X,Y,Z) <=> X=1,Y=0,Z=0. neg(Y,Z) , and(X,Y,Z) <=> X=0,Y=1,Z=0. neg(Z,Y) , and(X,Y,Z) <=> X=0,Y=1,Z=0. neg(X,Y) \ or(X,Y,Z) <=> Z=1. neg(Y,X) \ or(X,Y,Z) <=> Z=1. neg(X,Z) , or(X,Y,Z) <=> X=0,Y=1,Z=1. neg(Z,X) , or(X,Y,Z) <=> X=0,Y=1,Z=1. neg(Y,Z) , or(X,Y,Z) <=> X=1,Y=0,Z=1. neg(Z,Y) , or(X,Y,Z) <=> X=1,Y=0,Z=1. neg(X,Y) \ xor(X,Y,Z) <=> Z=1. neg(Y,X) \ xor(X,Y,Z) <=> Z=1. neg(X,Z) \ xor(X,Y,Z) <=> Y=1. neg(Z,X) \ xor(X,Y,Z) <=> Y=1. neg(Y,Z) \ xor(X,Y,Z) <=> X=1. neg(Z,Y) \ xor(X,Y,Z) <=> X=1. /* end of handler bool */