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.
/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With