你好 stackoverflow 社区,
我有一个序言代码,它为真值表创建子表达式,然后给它们值 true/false
它对于很多表达式都工作得很好,但是使用这个语句会发生这种情况
1 ?- phrase(subexprs(bicond(and(impl(A,B),impl(B,A)),bicond(A,B))),Subexprs), bindList([A,B]), maplist(expr_value, Subexprs, Values).
A = B, B = true,
Subexprs = [true impl true, true impl true, (true impl true)and(true impl true), true bicond true, **(true impl true)and(true impl true)bicond(true bicond true)**],
Values = [true, true, true, true, false] .
最后一个值不是应该打印的值
应该打印整个表达式,而不是
bicond((true impl true)and(true impl true),bicond true)
这是我的代码
and(A,B) :- A, B.
or(A,_) :- A.
or(_,B) :- B.
equ(A,B) :- or(and(A,B), and(not(A),not(B))).
xor(A,B) :- not(equ(A,B)).
nor(A,B) :- not(or(A,B)).
nand(A,B) :- not(and(A,B)).
impl(A,B) :- or(not(A),B).
bicond(true,true):-true.
bicond(true,false):-false.
bicond(false,true):-false.
bicond(false,false):-true.
:- op(900, fy,not).
:- op(910, yfx, and).
:- op(910, yfx, nand).
:- op(920, yfx, or).
:- op(920, yfx, nor).
:- op(930, yfx, impl).
:- op(930, yfx, equ).
:- op(930, yfx, xor).
:- op(910, yfx, bicond).
subexprs(V) -->
{ var(V), ! },
[].
subexprs(and(L, R)) -->
subexprs(L),
subexprs(R),
[and(L, R)].
subexprs(or(L, R)) -->
subexprs(L),
subexprs(R),
[or(L, R)].
subexprs(impl(L, R)) -->
subexprs(L),
subexprs(R),
[impl(L, R)].
subexprs(nand(L, R)) -->
subexprs(L),
subexprs(R),
[nand(L, R)].
subexprs(nor(L, R)) -->
subexprs(L),
subexprs(R),
[nor(L, R)].
subexprs(xor(L, R)) -->
subexprs(L),
subexprs(R),
[xor(L, R)].
subexprs(bicond(L, R)) -->
subexprs(L),
subexprs(R),
[bicond(L, R)].
expr_value(Expr, true) :-
call(Expr),
!.
expr_value(_Expr, false).
bind(true).
bind(false).
bindList([]).
bindList([V|Vs]) :- bind(V),bindList(Vs).
我认为错误的部分是操作
但我不知道如何解决它