1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Thom Fruehwirth ECRC 1991-1993
4 %% 910528 started boolean,and,or constraints
5 %% 910904 added xor,neg constraints
6 %% 911120 added imp constraint
7 %% 931110 ported to new release
8 %% 931111 added card constraint
9 %% 961107 Christian Holzbaur, SICStus mods
11 %% ported to hProlog by Tom Schrijvers June 2003
14 :- module(fulladder,[main/0,main/1]).
16 :- constraints and/3, or/3, xor/3, neg/2.
18 :- use_module(library(lists)).
20 %% and/3 specification
30 and(X,Y,1) <=> X=1,Y=1.
32 and(X,Y,A) \ and(X,Y,B) <=> A=B, chr_dummy.
33 and(X,Y,A) \ and(Y,X,B) <=> A=B, chr_dummy.
43 or(X,Y,0) <=> X=0,Y=0.
47 or(X,Y,A) \ or(X,Y,B) <=> A=B, chr_dummy.
48 or(X,Y,A) \ or(Y,X,B) <=> A=B, chr_dummy.
50 %% xor/3 specification
59 xor(1,X,Y) <=> neg(X,Y).
60 xor(X,1,Y) <=> neg(X,Y).
61 xor(X,Y,1) <=> neg(X,Y).
65 xor(X,Y,A) \ xor(X,Y,B) <=> A=B, chr_dummy.
66 xor(X,Y,A) \ xor(Y,X,B) <=> A=B, chr_dummy.
68 %% neg/2 specification
77 neg(X,Y) \ neg(Y,Z) <=> X=Z, chr_dummy.
78 neg(X,Y) \ neg(Z,Y) <=> X=Z, chr_dummy.
79 neg(Y,X) \ neg(Y,Z) <=> X=Z, chr_dummy.
80 %% Interaction with other boolean constraints
81 neg(X,Y) \ and(X,Y,Z) <=> Z=0, chr_dummy.
82 neg(Y,X) \ and(X,Y,Z) <=> Z=0, chr_dummy.
83 neg(X,Z) , and(X,Y,Z) <=> X=1,Y=0,Z=0.
84 neg(Z,X) , and(X,Y,Z) <=> X=1,Y=0,Z=0.
85 neg(Y,Z) , and(X,Y,Z) <=> X=0,Y=1,Z=0.
86 neg(Z,Y) , and(X,Y,Z) <=> X=0,Y=1,Z=0.
87 neg(X,Y) \ or(X,Y,Z) <=> Z=1, chr_dummy.
88 neg(Y,X) \ or(X,Y,Z) <=> Z=1, chr_dummy.
89 neg(X,Z) , or(X,Y,Z) <=> X=0,Y=1,Z=1.
90 neg(Z,X) , or(X,Y,Z) <=> X=0,Y=1,Z=1.
91 neg(Y,Z) , or(X,Y,Z) <=> X=1,Y=0,Z=1.
92 neg(Z,Y) , or(X,Y,Z) <=> X=1,Y=0,Z=1.
93 neg(X,Y) \ xor(X,Y,Z) <=> Z=1, chr_dummy.
94 neg(Y,X) \ xor(X,Y,Z) <=> Z=1, chr_dummy.
95 neg(X,Z) \ xor(X,Y,Z) <=> Y=1, chr_dummy.
96 neg(Z,X) \ xor(X,Y,Z) <=> Y=1, chr_dummy.
97 neg(Y,Z) \ xor(X,Y,Z) <=> X=1, chr_dummy.
98 neg(Z,Y) \ xor(X,Y,Z) <=> X=1, chr_dummy.
100 /* end of handler bool */
102 half_adder(X,Y,S,C) :-
106 full_adder(X,Y,Ci,S,Co) :-
107 half_adder(X,Y,S1,Co1),
108 half_adder(Ci,S1,S,Co2),
119 write(bench(bool ,N,Time,0,hprolog)),write('.'),nl.
131 full_adder(0,Y,C,1,NC),
136 full_adder(1,Y,C,0,NC),