I`m writing code on visual prolog 8, I have to write Adder and half adder, using the table of truth and use a basis 2-AND-NOT Schemes I made: half adder
and a full adder
Have you got any ideas, how to make this work?
In ISO Prolog, you could do the following:
halfadd(X, Y, Z, C) :-
Z is X xor Y,
C is X /\ Y.
fulladd(X, Y, C, Z, D) :-
halfadd(X, Y, H, J),
halfadd(H, C, Z, K),
D is J \/ K.
Looks right to me:
X Y C|Z D
-----+---
0 0 0|0 0
0 0 1|1 0
0 1 0|1 0
0 1 1|0 1
1 0 0|1 0
1 0 1|0 1
1 1 0|0 1
1 1 1|1 1
half_adder(A, B, S, C)
whereA
andB
are the input bits, andS
andC
are the sum and carry, respectively. For full adder, you'd havefull_adder(A, B, Cin, S, Cout)
with similar meaning, except here you'd have a carry input (Cin
) and a carry outputCout
.X and not (Y and Z)
in Prolog using the basicand/2
andnot/1
facts, you'd write it something like,and(Y, Z, AYZ), not(AYZ, NAYZ), and(X, NAYZ, R).
whereR
is the result. That should be enough to get you o the right path I think. I don't know if that image you posted is your own code or what. If you want help with specific problems in code you wrote, you need to copy the code to your question and ask it. Don't just put a link in the comments to an image.