在 Prolog 中构造 XOR/3
Constructing XOR/3 in Prolog
对于 /3 命题逻辑,我有以下子句。
statement(false).
statement(true).
not(false, true).
not(true, false).
and(false, false, false).
and(false, true, false).
and(true, false, false).
and(true, true, true).
or(false, false, false).
or(false, true, true).
or(true, false, true).
or(true, true, true).
implying(X, Y, Z) :- not(X, Not_X) , or(Not_X, Y, Z).
我将如何添加 XOR 子句?
这应该有效。
xor(false, false, false).
xor(false, true, true).
xor(true, false, true).
xor(true, true, false).
您可以使用其中一个 equivalences:选择第一个,(P ∨ Q) ∧ ¬ (P ∧ Q),
xor(P,Q,R) :-
or(P,Q,O),
and(P,Q,A),
not(A,N),
and(O,N,R).
你得到:
?- forall(xor(P,Q,R),writeln(xor(P,Q,R))).
xor(false,false,false)
xor(false,true,true)
xor(true,false,true)
xor(true,true,false)
true.
对于 /3 命题逻辑,我有以下子句。
statement(false).
statement(true).
not(false, true).
not(true, false).
and(false, false, false).
and(false, true, false).
and(true, false, false).
and(true, true, true).
or(false, false, false).
or(false, true, true).
or(true, false, true).
or(true, true, true).
implying(X, Y, Z) :- not(X, Not_X) , or(Not_X, Y, Z).
我将如何添加 XOR 子句?
这应该有效。
xor(false, false, false).
xor(false, true, true).
xor(true, false, true).
xor(true, true, false).
您可以使用其中一个 equivalences:选择第一个,(P ∨ Q) ∧ ¬ (P ∧ Q),
xor(P,Q,R) :-
or(P,Q,O),
and(P,Q,A),
not(A,N),
and(O,N,R).
你得到:
?- forall(xor(P,Q,R),writeln(xor(P,Q,R))).
xor(false,false,false)
xor(false,true,true)
xor(true,false,true)
xor(true,true,false)
true.