Prolog is a logic programming language associated with artificial intelligence and computational linguistics.
It's my First day of Prolog and here is the Half Added login in Prolog. It is not a solution but it just works.
for Xor -> if [(X and Y is low or X and Y is high) and sum is low. ] OR [ (if X is low and Y is high or X is high and Y is low) and Sum is high]
for and -> if (X is high and Y is High And Carry is high) OR [(if X is low and Y is low or X is low and Y is high or X is high and Y is low) and Carry is low]
low = 0 and high = 1
Output:
The half adder adds two binary digits called as augend and addend and produces two outputs as sum and carry; XOR is applied to both inputs to produce sum and AND gate is applied to both inputs to produce carry. The full adder adds 3 one bit numbers, where two can be referred to as operands and one can be referred to as bit carried in. And produces 2-bit output, and these can be referred to as output carry and sum.
Thank you!
It's my First day of Prolog and here is the Half Added login in Prolog. It is not a solution but it just works.
1 2 3 4 5 6 7 8 | high(1).
low(0).
xor(X,Y,Sum) :- (((low(X) , low(Y)) ; (high(X) , high(Y))) , low(Sum)) ; (((low(X) , high(Y)) ; (high(X) , low(Y))) ,high(Sum)).
and(X,Y,Carry) :- (high(X), high(Y), high(Carry)) ; (((low(X) , low(Y)) ; (low(X) , high(Y)) ; (high(X) , low(Y))) , low(Carry)).
half_adder(X,Y,Sum,Carry):- xor(X,Y,Sum) , and(X,Y,Carry).
|
for Xor -> if [(X and Y is low or X and Y is high) and sum is low. ] OR [ (if X is low and Y is high or X is high and Y is low) and Sum is high]
for and -> if (X is high and Y is High And Carry is high) OR [(if X is low and Y is low or X is low and Y is high or X is high and Y is low) and Carry is low]
low = 0 and high = 1
Output:
prolog task3.pl |
The half adder adds two binary digits called as augend and addend and produces two outputs as sum and carry; XOR is applied to both inputs to produce sum and AND gate is applied to both inputs to produce carry. The full adder adds 3 one bit numbers, where two can be referred to as operands and one can be referred to as bit carried in. And produces 2-bit output, and these can be referred to as output carry and sum.
Half - Adder Truth Table |