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).

halfadder(I1,I2,S,C) :-
    and(I1,I2,C), xor(I1,I2,S).

print_halfadder(I1,I2,S,C) :-
    halfadder(I1,I2,S,C), write(I1),write(' '),write(I2),write(' '),
    write(S),write(' '),write(C).

fulladder(I1,I2,Cin,S,Cout) :-
    xor(I1,I2,X1),
    and(I1,I2,A1),
    and(X1,Cin,A2),
    xor(Cin,X1,S),
    or(A1,A2,Cout).

print_fulladder(I1,I2,Cin,S,Cout) :-
   fulladder(I1,I2,Cin,S,Cout), write(I1),write(' '),write(I2),write(' '),
    write(Cin),write(' '),write(S),write(' '),write(Cout).


