prolog - 在 Prolog 中构造 XOR/3
问题描述
对于 /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 子句?
解决方案
您可以使用其中一个等价物:选择第一个,(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.
推荐阅读
- angular - Ngrx/effects:如何在通过 http 更新之前显示一个对话框
- npm - NPM office-to-pdf 使用 MeteorJS
- assembly - 函数适用于堆栈上的缓冲区,但不适用于 .data 或 .bss 部分?
- azure - Azure B2C OpenID 将身份验证委托给 Azure AD
- r - 在 dplyr 语句中循环平均周期
- javascript - Node.js - Uncaught SyntaxError: Unexpected token 'export'
- javascript - 如何在 Vue 插件中需要一个 css 文件
- python - 如何将 numpy.int64 分配给 torch.cuda.FloatTensor?
- xamarin - 使用 Span 时的网格布局项目顺序
- react-native - 我们如何在用 React Native 编写的移动应用程序中获取 GPS 位置