Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog implement and/2, or/2, nand/2, nor/2, xor/2 [closed]

I want to implement the following predicates in prolog and use them for truth-tables: and/2, or/2, nand/2, nor/2, xor/2

Maybe someone can show me how to implement and/2 for example so I can do the others myself and post them here.

like image 794
PROLOGik Avatar asked Dec 20 '22 22:12

PROLOGik


1 Answers

/2 is possible and actually very elegent.

and(A,B) :- A,B.
or(A,B) :- A;B.
nand(A,B) :- not(and(A,B)).
nor(A,B) :- not(or(A,B)).
xor(A,B) :- or(A,B), nand(A,B).

To use just replace A/B with true/false. For example:

?- and(true,true).
true.
?- and(false, true).
false.
like image 160
Cameron White Avatar answered Dec 25 '22 22:12

Cameron White