我正在用Prolog编写一个SAT求解器。这是我到目前为止所能想到的:
cst(true).
cst(false).
is_true(cst(true)).
is_false(cst(false)).
and(A,B) :-
is_true(A),
is_true(B).
or(A,B) :-
is_true(A),
is_false(B).
or(A,B) :-
is_false(A),
is_true(B).
or(A,B) :-
and(A,B).
% not(A) :- 我被not/1卡住了。谁能给我个提示?
请注意,我没有使用Prolog的否定来解释逻辑否定。因此,我实现了第二个谓词is_false(+F),如果公式F为假,则该谓词为真。
编辑:我的意思是标题中不是/1,而不是不/2!
发布于 2020-11-17 04:21:16
所以你的想法是好的,但没有可能嵌套你的条款。解决方案是使用像形式逻辑中的“解释”这样的谓词:在整个术语中拖动is_true或is_false:
is_true(cst(true)).
is_true(and(A,B)) :-
is_true(A),
is_true(B).
is_true(or(A,B)) :-
is_true(A),
is_false(B).
is_true(or(A,B)) :-
is_false(A),
is_true(B).
is_true(or(A,B)) :-
is_true(A),
is_true(B).
is_true(not(A)) :-
is_false(A).
is_false(cst(false)).
is_false(and(A,B)) :-
is_true(A),
is_false(B).
is_false(and(A,B)) :-
is_false(A),
is_true(B).
is_false(and(A,B)) :-
is_false(A),
is_false(B).
is_false(or(A,B)):-
is_false(A),
is_false(B).
is_false(not(A)) :-
is_true(A).
?- is_true( or(not(and(cst(true), cst(false))), cst(false)) ).
true.
?- is_true( or(not(and(cst(true), cst(true))), cst(false)) ).
false.
?- is_false( or(not(and(cst(true), cst(true))), cst(false)) ).
true.
?- is_false( or(not(and(cst(true), cst(false))), cst(false)) ).
false.https://stackoverflow.com/questions/64859192
复制相似问题